A. response.token should be response.body.token to access the token
B. cy.setCookie is not a valid Cypress command
C. The request method should be GET, not POST
D. Cookies cannot store authentication tokens
Solution
Step 1: Check response object structure
The token is usually inside response.body.token, not directly response.token.
Step 2: Validate cy.setCookie usage
cy.setCookie is a valid command to set cookies in Cypress.
Final Answer:
response.token should be response.body.token to access the token -> Option A
Quick Check:
Access token via response.body.token [OK]
Hint: Use response.body.token, not response.token [OK]
Common Mistakes:
Using response.token instead of response.body.token
Thinking cy.setCookie is invalid
Changing POST to GET incorrectly
5. You want to write a Cypress test that logs in using token-based authentication and then visits a protected page. Which sequence correctly achieves this?
A. Set dummy token cookie, then visit protected page
B. Visit protected page first, then request token and set cookie
C. Request token, set cookie, then visit protected page outside .then()
D. Request token, set cookie, then visit protected page inside .then() callback
Solution
Step 1: Understand asynchronous flow
Token must be set before visiting the protected page, so visit must happen after setting cookie inside .then().
Step 2: Analyze options
Request token, set cookie, then visit protected page inside .then() callback sets cookie and visits page inside .then(), ensuring correct order and token availability.
Final Answer:
Request token, set cookie, then visit protected page inside .then() callback -> Option A
Quick Check:
Set token cookie before visiting page inside .then() [OK]
Hint: Visit protected page only after setting token cookie inside .then() [OK]
Common Mistakes:
Visiting page before setting token cookie
Setting cookie outside async callback
Using dummy tokens without real login
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.