Bird
0
0

You want to test that a user stays logged in after a page reload by preserving the auth_token cookie. Which Cypress approach correctly achieves this?

hard📝 Application Q15 of 15
Cypress - Authentication and Sessions
You want to test that a user stays logged in after a page reload by preserving the auth_token cookie. Which Cypress approach correctly achieves this?
AUse <code>cy.reload(preserveCookies: true)</code> to keep cookies
BUse <code>cy.preserveCookie('auth_token')</code> before reload
CUse <code>cy.clearCookies()</code> before reload to reset cookies
DUse <code>cy.getCookie('auth_token').then(cookie => { cy.setCookie(cookie.name, cookie.value) })</code> after reload
Step-by-Step Solution
Solution:
  1. Step 1: Understand cookie preservation

    Cypress clears cookies on reload by default, so to keep a cookie, you must reset it after reload.
  2. Step 2: Analyze options

    Use cy.getCookie('auth_token').then(cookie => { cy.setCookie(cookie.name, cookie.value) }) after reload manually gets and sets the cookie again after reload, which preserves it correctly. Use cy.preserveCookie('auth_token') before reload is invalid syntax. Use cy.clearCookies() before reload to reset cookies clears cookies, which removes the token. Use cy.reload({ preserveCookies: true }) to keep cookies is not a valid reload option in Cypress.
  3. Final Answer:

    Use cy.getCookie('auth_token').then(cookie => { cy.setCookie(cookie.name, cookie.value) }) after reload -> Option D
  4. Quick Check:

    Manually reset cookie after reload to preserve [OK]
Quick Trick: Manually reset cookie after reload to keep it [OK]
Common Mistakes:
  • Assuming reload keeps cookies automatically
  • Using non-existent preserveCookie command
  • Clearing cookies before reload by mistake

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes