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?
✗ Incorrect
cy.session() saves and restores session data like cookies and local storage to preserve state between tests.
Why is preserving state between tests useful?
✗ Incorrect
Preserving state helps tests run faster by reusing login sessions or data instead of repeating setup steps.
What is a risk of relying too much on preserved state in tests?
✗ Incorrect
Tests should be independent. Preserved state can cause hidden bugs and make debugging harder.
Which of these is NOT a way to preserve state in Cypress?
✗ Incorrect
cy.clearLocalStorage() clears data and does not preserve state.
To preserve local storage between tests, you should:
✗ Incorrect
Custom commands like cy.saveLocalStorage() and cy.restoreLocalStorage() help keep local storage data between tests.
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.