-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot clear cookie set on multiple subdomains #5723
Comments
We will need a fully reproducible example provided. We have tests for clearing cookies and likely there is something more complex involved where your issue is occuring. Provide a complete example or we cannot move forward with fixing your issue. |
Pretty straightforward problem.. simple provide a way to clear a cookie which was whitelisted before. The login function has this inside (so we dont have to login before each test): Cypress.Cookies.defaults({
whitelist: ['jwt-token','csrf-token']
}); During the testing I need to login as different user to test its profile.. the way to do it is to clear |
Here is my workaround to clear cookies that are set using it("Clear browser cookies and localstorage", function(){
//Visit URL
const host_url = Cypress.env('host_url');
cy.visit(host_url)
// Empty defaults
Cypress.Cookies.defaults({
whitelist: []
});
//Clear localStrage
cy.clearLocalStorage()
//Clear Cookies
cy.clearCookies()
// Set defaults
Cypress.Cookies.defaults({
whitelist: /wordpress_.*|woocommerce_.*|wp_woocommerce_.*/
})
}) |
We see the same issue after upgrade to 3.5.0+ of Cypress (going to check 3.8.1 today and see if it will help). It's not possible to reproduce it since it's flaky. |
We were able to identify the root cause of "inconsistency" on our side. The reason was in fact that we had two cookies with the same name but different domains. There is certainly a difference in behaviour between 3.4.1 and 3.5.0 but I'm not 100% sure if it's expected or not. @jennifer-shehane, this is how it can be reproduced:
{
"baseUrl": "https://dev.mysql.com",
"integrationFolder": "cypress/integration",
"testFiles": "**/*.js",
"screenshotOnRunFailure": false,
"video": false
}
describe('clearCookie', () => {
it('should remove all cookies with specified name', () => {
cy.setCookie('test_cookie', 'value1', {
domain: 'mysql.com'
})
cy.setCookie('test_cookie', 'value2', {
domain: 'dev.mysql.com'
})
cy.getCookie('test_cookie')
.should('exist')
cy.clearCookie('test_cookie')
cy.getCookie('test_cookie')
.should('not.exist')
})
}) docker run -it -v $PWD:/e2e -w /e2e cypress/included:3.4.1
docker run -it -v $PWD:/e2e -w /e2e cypress/included:3.5.0
|
I can still reproduce the issue provided by @aelmekeev. The cookie is not removed in Cypress 3.5.0+.
{
"baseUrl": "https://dev.mysql.com"
}
it('should remove all cookies with specified name', () => {
cy.setCookie('test_cookie', 'value1', {
domain: 'mysql.com'
})
cy.setCookie('test_cookie', 'value2', {
domain: 'dev.mysql.com'
})
cy.getCookie('test_cookie').should('exist').then((cookie) => {
cy.log(cookie)
})
cy.clearCookie('test_cookie')
cy.getCookie('test_cookie').should('not.exist')
}) 3.4.13.5.0 |
The code for this is done in cypress-io/cypress#24692, but has yet to be released. |
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
As mentioned here using command
cy.clearCookie('nameOfCookie')
we should be able to delete cookie no matter what.. but apparently since then behaviour has changed..Didn't find an official way to clear the whitelist so tried setting defaults back to undefined or empty array - no effect whatsoever..
Cypress v
3.5.0
.Any other ideas how to remove the cookie which was whitelisted before?? Thx
The text was updated successfully, but these errors were encountered: