Skip to main content

Cypress.session

Cypress.session is a collection of session-related helper methods intended to be used alongside the cy.session() command.

caution
Experimental

The session API is currently experimental, and can be enabled by setting the experimentalSessionSupport flag to true in the Cypress config or by using Cypress.config() at the top of a spec file.

Enabling this flag does the following:

  • It adds the cy.session() command for use in tests.
  • It adds the Cypress.session API.
  • It adds the following new behaviors (that will be the default in a future major update of Cypress) at the beginning of each test:
    • The page is cleared (by setting it to about:blank).
    • All active session data (cookies, localStorage and sessionStorage) across all domains are cleared.
  • It overrides the Cypress.Cookies.preserveOnce() and Cypress.Cookies.defaults() methods.

Because the page is cleared before each test, cy.visit() must be explicitly called in each test to visit a page in your application.

Syntax

Clear all saved sessions and re-run the current spec file.

Cypress.session.clearAllSavedSessions()

This can also be done by clicking the "Clear All Sessions" button in the Sessions Instrument Panel.

Sessions Instrument Panel

See also