cypress-v10-preserve-cookie
v1.2.1
Published
Cypress.Cookies.preserveOnce for Cypress v10
Downloads
232,608
Maintainers
Readme
cypress-v10-preserve-cookie
Cypress.Cookies.preserveOnce for Cypress v10
Install
# if using NPM
$ npm i -D cypress-v10-preserve-cookie
# if using Yarn
$ yarn add -D cypress-v10-preserve-cookie
Import this module from your spec file or from your support file
import 'cypress-v10-preserve-cookie'
This module adds a custom command cy.preserveCookieOnce
Use
Single cookie
// login sets the cookie like "connect.session" for example
before(loginSomehow)
beforeEach(() => {
// equivalent to cy.preserveCookieOnce('connect.session')
cy.preserveCookieOnce('connect.session')
})
it('is logged in', () => {
...
})
it('is still logged in', () => {
...
})
Multiple cookies
You can pass multiple cookie names
cy.preserveCookieOnce(
'connect.session',
'refresh_token',
'access_token',
)
// equivalent to
cy.preserveCookieOnce('connect.session')
cy.preserveCookieOnce('refresh_token')
cy.preserveCookieOnce('access_token')
Types
Included in src/index.d.ts
Debugging
This module uses debug module to output verbose browser console messages when needed. To turn the logging on, open the browser's DevTools console and set the local storage entry:
localStorage.debug = 'cypress-v10-preserve-cookie'
If you re-run the tests, you should see the messages appear in the console.
Examples
See also
If you need more control over storing/restoring cookies/users/any other data, check out my plugin cypress-data-session.
Small print
Author: Gleb Bahmutov <[email protected]> © 2022
- @bahmutov
- glebbahmutov.com
- blog
- videos
- presentations
- cypress.tips
- Cypress Tips & Tricks Newsletter
- my Cypress courses
License: MIT - do anything with the code, but don't blame me if it does not work.
Support: if you find any problems with this module, email / tweet / open issue on Github