Unexpected bahaviour.
Cookies are automatically flushed between tests (as per the documentation).
Have an option to not flush cookies between tests for more control.
describe('Set cookie', function() {
it('Sets cookie', function() {
cy.setCookie('test', '1');
});
});
describe('Get cookie', function() {
it('Gets cookie', function() {
cy.getCookie('test').should('have.property', 'value', '1')
});
});
There is an API to preserve cookies in between tests: https://docs.cypress.io/api/cypress-api/cookies.html
I'm closing this issue in favor of this one (below) because it goes in length to explain why what we do by default is a bad idea and what needs to change. It's a priority but its underneath other things unfortunately.
This will preserve cookies in every test
beforeEach(() => {
// Preserve cookie in every test
Cypress.Cookies.defaults({
whitelist: (cookie) => {
return true;
}
})
});
For those arriving from the future, starting in version 5.0.0 the Cypress.Cookies.defaults()
whitelist
option has been renamed to preserve
to more closely reflect its behavior. Addressed in #7782.
https://docs.cypress.io/guides/references/changelog.html#5-0-0
Most helpful comment
For those arriving from the future, starting in version 5.0.0 the
Cypress.Cookies.defaults()
whitelist
option has been renamed topreserve
to more closely reflect its behavior. Addressed in #7782.https://docs.cypress.io/guides/references/changelog.html#5-0-0