0
0
Cypresstesting~5 mins

Preserving state between tests in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does 'preserving state between tests' mean in Cypress?
It means keeping certain data like cookies or local storage so tests can share the same session or user state without logging in again.
Click to reveal answer
intermediate
How can you preserve cookies between tests in Cypress?
Use cy.getCookie() and cy.setCookie() or use Cypress.Cookies.preserveOnce() inside beforeEach() hooks to keep cookies across tests.
Click to reveal answer
intermediate
What is the purpose of cy.session() in Cypress?
cy.session() helps save and restore browser session data like cookies and local storage to speed up tests and keep user state between tests.
Click to reveal answer
beginner
Why should tests avoid relying on preserved state when possible?
Because tests should be independent and repeatable. Relying on preserved state can hide bugs and make tests harder to debug.
Click to reveal answer
advanced
Which Cypress command helps preserve local storage between tests?
You can use cy.restoreLocalStorage() and cy.saveLocalStorage() with custom commands or plugins to keep local storage data between tests.
Click to reveal answer
Which Cypress command is designed to save and restore session data between tests?
Acy.reload()
Bcy.session()
Ccy.visit()
Dcy.clearCookies()
Why is preserving state between tests useful?
ATo speed up tests by avoiding repeated logins
BTo make tests dependent on each other
CTo hide bugs in the application
DTo clear all data after each test
What is a risk of relying too much on preserved state in tests?
ATests become slower
BTests may fail randomly
CTests lose independence and may hide bugs
DTests cannot run in parallel
Which of these is NOT a way to preserve state in Cypress?
ASaving cookies manually
BUsing cy.preserveOnce()
CUsing cy.session()
DUsing cy.clearLocalStorage()
To preserve local storage between tests, you should:
AUse cy.saveLocalStorage() and cy.restoreLocalStorage() custom commands
BUse cy.clearCookies()
CReload the page after each test
DAvoid using local storage
Explain how you can preserve user login state between Cypress tests and why it is helpful.
Think about saving cookies or session data to avoid logging in every test.
You got /4 concepts.
    Describe the risks of relying on preserved state between tests and how to balance it with test independence.
    Consider test reliability and debugging.
    You got /4 concepts.