A. Test passes because cookie 'token' has value 'xyz789'
B. Test fails because cookie 'token' is not set
C. Syntax error due to wrong command usage
D. Test passes but cookie value is empty string
Solution
Step 1: Analyze cookie setting
The code sets a cookie named 'token' with value 'xyz789' using cy.setCookie.
Step 2: Analyze assertion
The code gets the cookie 'token' and asserts its value property equals 'xyz789'. This matches the set value.
Final Answer:
Test passes because cookie 'token' has value 'xyz789' -> Option A
Quick Check:
Set cookie then assert value = Pass [OK]
Hint: Set cookie then assert value matches to pass test [OK]
Common Mistakes:
Assuming getCookie returns undefined if setCookie was called
Confusing property name in assertion
Thinking syntax is incorrect
4. Identify the error in this Cypress code that tries to clear all cookies:
cy.clearCookie()
medium
A. clearCookie clears all cookies without arguments, so no error
B. clearCookie requires a cookie name argument to clear a specific cookie
C. clearCookie is not a valid Cypress command
D. clearCookie must be called with an array of cookie names
Solution
Step 1: Understand clearCookie usage
cy.clearCookie() requires a cookie name string to clear one cookie.
Step 2: How to clear all cookies
To clear all cookies, use cy.clearCookies() (note plural) without arguments.
Final Answer:
clearCookie requires a cookie name argument to clear a specific cookie -> Option B
Quick Check:
clearCookie needs name; clearCookies clears all [OK]
Hint: Use clearCookies() to clear all, clearCookie(name) for one [OK]
Common Mistakes:
Calling clearCookie() without name to clear all
Confusing clearCookie with clearCookies
Assuming clearCookie accepts multiple names
5. 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
A. Use cy.reload(preserveCookies: true) to keep cookies
B. Use cy.preserveCookie('auth_token') before reload
C. Use cy.clearCookies() before reload to reset cookies
D. Use cy.getCookie('auth_token').then(cookie => { cy.setCookie(cookie.name, cookie.value) }) after reload
Solution
Step 1: Understand cookie preservation
Cypress clears cookies on reload by default, so to keep a cookie, you must reset it after reload.
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.
Final Answer:
Use cy.getCookie('auth_token').then(cookie => { cy.setCookie(cookie.name, cookie.value) }) after reload -> Option D
Quick Check:
Manually reset cookie after reload to preserve [OK]
Hint: 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
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.