Bird
0
0

Which of the following is the correct Cypress command syntax to store a token from a response into a variable named authToken?

easy📝 Syntax Q3 of 15
Cypress - Authentication and Sessions
Which of the following is the correct Cypress command syntax to store a token from a response into a variable named authToken?
Acy.request('POST', '/login').then(response => { authToken = response.body.auth })
Bcy.request('POST', '/login').then(response => authToken = response.token)
Ccy.request('POST', '/login').then(response => { authToken = response.token })
Dcy.request('POST', '/login').then(response => { authToken = response.body.token })
Step-by-Step Solution
Solution:
  1. Step 1: Understand Cypress response structure

    Cypress response object stores data in response.body. The token is usually inside body.token.
  2. Step 2: Check correct syntax for arrow function and assignment

    cy.request('POST', '/login').then(response => { authToken = response.body.token }) correctly uses a block arrow function and accesses response.body.token to assign to authToken.
  3. Final Answer:

    cy.request('POST', '/login').then(response => { authToken = response.body.token }) -> Option D
  4. Quick Check:

    Correct token assignment syntax = cy.request('POST', '/login').then(response => { authToken = response.body.token }) [OK]
Quick Trick: Access token via response.body.token in Cypress [OK]
Common Mistakes:
  • Accessing token directly on response instead of response.body
  • Missing curly braces for block arrow function
  • Using wrong property name like response.body.auth

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes