Bird
0
0

Which of the following is the correct way to use cy.request to send login credentials via POST in Cypress?

easy📝 Syntax Q3 of 15
Cypress - Authentication and Sessions
Which of the following is the correct way to use cy.request to send login credentials via POST in Cypress?
Acy.request('POST', '/login', 'username=user&password=pass')
Bcy.request({ method: 'GET', url: '/login', body: { username: 'user', password: 'pass' } })
Ccy.request('POST', '/login', { username: 'user', password: 'pass' })
Dcy.request({ url: '/login', method: 'POST', data: { username: 'user', password: 'pass' } })
Step-by-Step Solution
Solution:
  1. Step 1: Use the correct HTTP method

    Login requests typically use POST to send credentials securely.
  2. Step 2: Use the correct cy.request syntax

    The syntax cy.request('POST', url, body) is valid and straightforward.
  3. Step 3: Avoid incorrect options

    cy.request({ method: 'GET', url: '/login', body: { username: 'user', password: 'pass' } }) uses GET instead of POST; cy.request('POST', '/login', 'username=user&password=pass') sends data as a string, which is not standard; cy.request({ url: '/login', method: 'POST', data: { username: 'user', password: 'pass' } }) uses 'data' instead of 'body'.
  4. Final Answer:

    cy.request('POST', '/login', { username: 'user', password: 'pass' }) -> Option C
  5. Quick Check:

    POST method with body object is correct syntax [OK]
Quick Trick: Use POST method with body object for login [OK]
Common Mistakes:
  • Using GET instead of POST for login
  • Passing credentials as a query string
  • Using 'data' instead of 'body' in request options

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes