Cypress.Cookies.preserveOnce f

cypress-v10-preserve-cookie

Cypress.Cookies.preserveOnce for Cypress v10

How To Preserve Cookie Once In 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 bahmutov/cypress-v10-preserve-cookie-example preserve a list of cookies by name all.cy.js preserve any cookies set by the application unknown.cy.js 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

@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

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。