Cypress: Option to not flush cookies between tests

Created on 26 Nov 2017  路  3Comments  路  Source: cypress-io/cypress

  • Operating System: OSX 10.12.6 (16G1036)
  • Cypress Version: 1.1.1
  • Browser Version: 62.0.3202.94

Is this a Feature or Bug?

Unexpected bahaviour.

Current behavior:

Cookies are automatically flushed between tests (as per the documentation).

image

Desired behavior:

Have an option to not flush cookies between tests for more control.

How to reproduce:

  1. Write a first test that sets a cookie to the domain;
  2. Write a second test that should utilise this cookie;
  3. The cookie from the first test is flushed and is not available in the second test.

Test code:

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')
  });
});

Most helpful comment

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

All 3 comments

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.

https://github.com/cypress-io/cypress/issues/686

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

Was this page helpful?
0 / 5 - 0 ratings