Whitelisted cookies preserved over runs, clearCookies() does not clear whitelisted cookies
See original GitHub issue-
Operating System: OSX 10.12.5
-
Cypress Version: Cypress package version: 1.0.2 Cypress binary version: 1.0.2
-
Browser Version: Canary 64
Is this a Feature or Bug?
Bug
Current behavior:
Having the following test code:
describe('Example', () => {
Cypress.Cookies.defaults({
whitelist: /SESSION_COOKIE/
});
before('we should log in first', () => {
cy
// clearCookies() does not clear whitelisted cookies
.clearCookies()
.visit('application_url, which sets a NEW SESSION_COOKIE to use throughout the following tests');
});
it('should still have SESSION_COOKIE', function() {
cy
.visit('application_url/subpage')
.wait(5000);
// .wait() was just added so you can inspect the list of cookies.
// Notice that SESSION_COOKIE stays the same over several runs.
});
it('should really still have SESSION_COOKIE', function() {
// More tests.
cy
.visit('application_url/subpage')
.wait(5000);
});
it('should really really still have SESSION_COOKIE', function() {
// More and more tests.
cy
.visit('application_url/subpage')
.wait(5000);
});
});
In the current phase my tests keeps failing, because the first run logs in and because I preserve the cookie, it is persisted throughout every test that runs.
Technically I’m not able to clear cookies between runs/during tests.
Desired behavior:
Few suggestions 😃
- clearCookies() should be able to remove all cookies, even whitelisted cookies (to avoid a breaking change, it can be an option to clearCookies(), e.g. clearWhitelisted: true ?)
- Next to ‘preserveOnce()’ I’d also rather see a ‘preserve’ that will at least preserve the cookies throughout the test suite (test suite = 1 file). If I want to achieve what I actually want right now I have to call preserveOnce() in every single test.
How to reproduce:
Use the above code, start coding on the test and press Save. Cypress will run the test, but preserve the whitelisted cookie even though it says ‘clearCookies()’. Also when you use the ‘Run all tests’.
Test code:
See above 😃
Additional Info (images, stack traces, etc)
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
When set to clear cookies on exit, the whitelisted sites is also ...
When I have Edge set to clear cookies on exit, websites I list under "Don't clear" disappear each time I close and relaunch....
Read more >Clear, enable, and manage cookies in Chrome - Google Support
Clear, enable, and manage cookies in Chrome. You can choose to delete existing cookies, allow or block all cookies, and set preferences for...
Read more >Cookies - Cypress Documentation
Log when cookie values are created, modified or deleted. By turning on debugging, Cypress will automatically generate logs to the console when it...
Read more >Preserve cookies / localStorage session across tests in Cypress
To update this thread, there is already a better solution available for preserving cookies (by @bkucera); but now there is a workaround ...
Read more >Does Keeping a Cookie "Whitelist" Slow Down Chrome?
I would think scenario B, with cookies being blocked and specific websites whitelisted would be more of a negative impact on webpage ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Also if you want to clear a cookie even if its been preserved you can just do
cy.clearCookie('nameOfCookie')
That will blow it away no matter what.
And here is my workaround to clear cookies that are set using
whitelist
regex and set them again: