0
0
Cypresstesting~5 mins

cy.session() for session caching in Cypress - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is cy.session() used for in Cypress?

cy.session() is used to cache and restore browser sessions to speed up tests by avoiding repeated login or setup steps.

Click to reveal answer
beginner
How does cy.session() improve test performance?

It saves the session state once and reuses it in later tests, so Cypress does not need to repeat login or setup actions every time.

Click to reveal answer
beginner
What are the two main arguments of cy.session()?

The first is a unique session identifier (like a username). The second is a callback function that sets up the session (like logging in).

Click to reveal answer
intermediate
True or False: cy.session() automatically clears cookies and local storage before restoring a session.

True. Cypress clears cookies, local storage, and session storage before restoring the cached session to avoid conflicts.

Click to reveal answer
intermediate
What should you do if your session setup changes and cy.session() returns stale data?

You can force Cypress to recreate the session by changing the session id or clearing the session cache.

Click to reveal answer
What is the primary benefit of using cy.session() in Cypress tests?
AAutomatically generating test data
BSpeeding up tests by caching login sessions
CRunning tests in parallel
DTaking screenshots during tests
Which of the following is NOT cleared automatically before restoring a session with cy.session()?
ABrowser Cache
BLocal Storage
CSession Storage
DCookies
What is the first argument to cy.session() typically used for?
AThe URL to visit
BThe browser type
CThe test name
DA unique session identifier
If your login process changes, how can you ensure cy.session() uses the updated session?
AUse <code>cy.reload()</code> after login
BRestart the browser manually
CChange the session id or clear the session cache
DNothing, it updates automatically
Which Cypress command is commonly used inside the cy.session() callback to set up the session?
Acy.visit() and cy.get() to perform login steps
Bcy.request() to clear cookies
Ccy.screenshot() to capture the page
Dcy.wait() to pause the test
Explain how cy.session() helps speed up Cypress tests and describe its basic usage.
Think about how you avoid logging in every time manually.
You got /4 concepts.
    Describe what happens internally when Cypress restores a session using cy.session().
    Consider what needs to be cleaned before restoring to avoid conflicts.
    You got /4 concepts.