Bird
0
0

Which of the following is the correct way to preserve a cookie named 'user_session' only for the duration of a test suite in Cypress?

easy📝 Syntax Q3 of 15
Cypress - Authentication and Sessions
Which of the following is the correct way to preserve a cookie named 'user_session' only for the duration of a test suite in Cypress?
AbeforeEach(() => { Cypress.Cookies.preserveOnce('user_session') })
Bbefore(() => { Cypress.Cookies.preserveOnce('user_session') })
CafterEach(() => { Cypress.Cookies.preserveOnce('user_session') })
DbeforeEach(() => { cy.preserveCookie('user_session') })
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct lifecycle hook

    Preserving cookies between tests requires calling preserveOnce in beforeEach to run before every test.
  2. Step 2: Use correct Cypress API

    Cypress.Cookies.preserveOnce('cookieName') is the correct method; cy.preserveCookie does not exist.
  3. Final Answer:

    beforeEach(() => { Cypress.Cookies.preserveOnce('user_session') }) -> Option A
  4. Quick Check:

    Preserve cookies in beforeEach using Cypress.Cookies.preserveOnce [OK]
Quick Trick: Use beforeEach with Cypress.Cookies.preserveOnce [OK]
Common Mistakes:
  • Using before instead of beforeEach
  • Calling preserveOnce in afterEach
  • Using non-existent cy.preserveCookie command

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes