lecture 7 of 150 completed

Logging in without wasting minutes

cy.session saves the login once and reuses it, without making your tests depend on each other.

What you'll learn

  • How cy.session removes repeated logins
  • How to key and validate a cached session
  • Why a mutated session leaks into later tests

Logging in through the form takes about three seconds. That sounds small. With eighty tests, it is four minutes of every single run, just typing the same password.

You might think: why not log in once at the start, and let the other tests use that session?

Please do not. That is exactly the trap from the last lecture. Your tests would depend on each other. Run one test alone and it fails, because nobody logged in for it.

Cypress has a proper solution: cy.session. It runs your login once, saves the result, and gives it back to the next test instead of doing the steps again.

full course

Keep reading with the full course

The Foundations track and the first lessons in each framework are free. This lesson needs full course access. A course plan includes all lessons for Playwright, Cypress and Selenium.

See course plans →