Bird
0
0

You want to preserve multiple cookies named 'token' and 'user_id' across all tests without calling preserveOnce in every test. Which is the best way to do this in Cypress?

hard📝 framework Q15 of 15
Cypress - Authentication and Sessions
You want to preserve multiple cookies named 'token' and 'user_id' across all tests without calling preserveOnce in every test. Which is the best way to do this in Cypress?
ADisable cookie clearing globally with Cypress.config
BCall Cypress.Cookies.preserveOnce('token', 'user_id') in each test
CSet cookies again in every test manually
DUse Cypress.Cookies.defaults({ whitelist: ['token', 'user_id'] }) in support file
Step-by-Step Solution
Solution:
  1. Step 1: Understand preserving multiple cookies globally

    Using Cypress.Cookies.defaults with a preserve array keeps specified cookies across all tests automatically.
  2. Step 2: Compare with other options

    Calling preserveOnce in every test is repetitive. Manually setting cookies each time is inefficient. Disabling cookie clearing globally is not recommended.
  3. Final Answer:

    Use Cypress.Cookies.defaults({ whitelist: ['token', 'user_id'] }) in support file -> Option D
  4. Quick Check:

    Defaults preserve multiple cookies globally [OK]
Quick Trick: Use Cypress.Cookies.defaults to preserve cookies globally [OK]
Common Mistakes:
  • Calling preserveOnce repeatedly instead of defaults
  • Manually resetting cookies each test
  • Trying to disable cookie clearing globally

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes