Login using Cypress Session()
This article is about how to login into app before every test using cy.session API command.
Usually in Test Automation, we may repeat running the login scenario before each test which will eat up our test execution time. To avoid this problem, Cypress has a ‘session’ command.
Using this command, can login into app only once and the session details will be stored and used for further login. This command will Cache and restore cookies, localStorage
, and sessionStorage
in order to reduce test setup times.
The session API is currently experimental, and can be enabled by setting the experimentalSessionAndOrigin option to true in the Cypress config.
Enabling this flag does the following:
- It adds the cy.session() and cy.origin() commands, and 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.
Sample application url is: