I have brought cypress into a Laravel app and am doing some testing with axios.post
requests. I have figured out how to get cypress to work in terms of preserving
the xsrf token
so that the axios
call can finish it's process. The issue is that when I attempt to clear the cookie in the localized test it does not work. The next time I open the test my user is already logged into their account so the cookie is not being reset each time the test runs. Am I doing this improperly?
Cypress/Support/index.js
Cypress.Cookies.defaults({
preserve: ["XSRF-TOKEN", "myapp_session", "remember_token"]
});
Inside of an it()
in my cypress test. At this point the user is authenticated and a form is being filled out. This is the point of form submission on click. When the button is clicked an axios.post()
request is sent. The post is working as expected, again I just want to user to have to re-authenticate once the test restarts.
//Submit the form
cy.get('[data-cy=system-create-submit]').click()
cy.wait(4500)
cy.location('pathname').should('eq', '/system')
//cy.getCookie('myapp_session') // clear the 'myapp_session' cookie
//Update as of 10.29.21
cy.clearCookie('myapp_session')
If I close and open restart the test the user is still authenticated even though the first step in the test is to log the user in.
CodePudding user response:
It looks like the command you are looking for is
cy.clearCookie('myapp_session')