Bird
0
0

What is wrong with this code?

medium📝 Debug Q7 of 15
Cypress - Authentication and Sessions
What is wrong with this code?
cy.session('member', () => {
  cy.visit('/login')
  cy.get('#username').type('member')
  cy.get('#password').type('pass')
  cy.get('button[type=submit]').click()
})
cy.session('member')
AYou cannot use <code>cy.visit()</code> inside <code>cy.session()</code>
BThe selector <code>button[type=submit]</code> is invalid syntax
CCalling <code>cy.session('member')</code> without a callback after defining it causes an error
DThe session name 'member' must be unique per test file
Step-by-Step Solution
Solution:
  1. Step 1: Review usage of cy.session()

    When calling cy.session() with a name only, it attempts to restore the session.
  2. Step 2: Check the code

    The code defines the session with a callback, then calls cy.session('member') again without a callback.
  3. Step 3: Identify the problem

    Calling cy.session() with the same name but no callback is valid to restore, but here it is redundant and may cause confusion or errors if misused.
  4. Final Answer:

    Calling cy.session('member') without a callback after defining it causes an error -> Option C
  5. Quick Check:

    Is calling cy.session with name only valid after definition? [OK]
Quick Trick: Define session once with callback, restore without callback [OK]
Common Mistakes:
  • Calling cy.session with name only before defining it
  • Misunderstanding selector syntax
  • Thinking cy.visit is disallowed inside cy.session

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes