Bird
0
0

How can you use cy.visit() to navigate to a page and set a custom HTTP header for the request?

hard📝 Application Q9 of 15
Cypress - Navigation and URL
How can you use cy.visit() to navigate to a page and set a custom HTTP header for the request?
Acy.visit('https://site.com', { authHeader: 'token' })
Bcy.visit('https://site.com', { headers: { 'Authorization': 'token' } })
Ccy.visit('https://site.com', { header: { 'Authorization': 'token' } })
Dcy.visit('https://site.com', { headers: 'Authorization: token' })
Step-by-Step Solution
Solution:
  1. Step 1: Know the correct option key for headers

    The option key is headers and it expects an object of header keys and values.
  2. Step 2: Check the format of headers

    Headers must be an object, not a string or incorrectly named key.
  3. Final Answer:

    cy.visit('https://site.com', { headers: { 'Authorization': 'token' } }) -> Option B
  4. Quick Check:

    Use { headers: { key: value } } to set HTTP headers [OK]
Quick Trick: Set headers as object inside options in cy.visit() [OK]
Common Mistakes:
  • Using wrong option keys
  • Passing headers as string
  • Misspelling 'headers'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes