bahmutov / cypress-v10-preserve-cookie

Cypress.Cookies.preserveOnce for Cypress v10

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cypress-v10-preserve-cookie cypress version ci

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.

Show debug messages

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 <gleb.bahmutov@gmail.com> © 2022

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

About

Cypress.Cookies.preserveOnce for Cypress v10

License:MIT License


Languages

Language:JavaScript 100.0%