Can Cypress retain browser information/data and not start a new session?

Viewed 162

I'm running a test where it should be beneficial if Cypress didn't renew the browser session/remove cache/cookies, etc, so it essentially retained all the information i've inputted previously.

Is this possible?

1 Answers

Maybe try the cy.session() command, which is like a cache for cookies, localstorage, and session.

The only downside as far as I can see is you need to do all the setting (requests, etc) inside the cy.session() setup callback.

For example

beforeEach(() => {
  cy.session('init', () => {
    // request and set cookies
  })
})

it('first test', () => {
  // the beforeEach() for 1st test will fire the request
  ...
})

it('second test', () => {
  // the beforeEach() for 2nd test will set same values as before from cache
  // and not resend the request 
})

Note there's an flag that needs to be set in config

experimentalSessionAndOrigin: true
Related