Bird
0
0

Which of the following is the correct syntax to create a session with cy.session()?

easy📝 Syntax Q12 of 15
Cypress - Authentication and Sessions
Which of the following is the correct syntax to create a session with cy.session()?
Acy.session('user', () => { cy.login() })
Bcy.session('user', cy.login())
Ccy.session('user', function cy.login())
Dcy.session('user', cy.login)
Step-by-Step Solution
Solution:
  1. Step 1: Recall cy.session() syntax

    The second argument must be a callback function that runs login steps, e.g., () => { cy.login() }.
  2. Step 2: Check each option

    Only cy.session('user', () => { cy.login() }) correctly passes a callback function. The other options pass a function reference incorrectly, execute the function immediately, or use invalid syntax.
  3. Final Answer:

    cy.session('user', () => { cy.login() }) -> Option A
  4. Quick Check:

    Callback function syntax = cy.session('user', () => { cy.login() }) [OK]
Quick Trick: Use arrow function for session callback: () => { ... } [OK]
Common Mistakes:
  • Passing function call instead of function
  • Using invalid function syntax
  • Omitting the callback wrapper

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes