Bird
0
0

What will happen when the following code runs?

medium📝 Predict Output Q4 of 15
Cypress - Authentication and Sessions
What will happen when the following code runs?
cy.session('admin', () => {
  cy.visit('/login')
  cy.get('#username').type('admin')
  cy.get('#password').type('password')
  cy.get('button[type=submit]').click()
})
cy.session('admin')
AThe session is cleared after the first call
BThe login steps run every time cy.session('admin') is called
CThe login steps run only once; subsequent calls reuse the session
DThe test will fail due to missing callback in second cy.session call
Step-by-Step Solution
Solution:
  1. Step 1: Understand session caching behavior

    The first call creates and caches the session by running login steps.

  2. Step 2: Analyze second call

    Calling cy.session('admin') reuses cached session without rerunning login.

  3. Final Answer:

    The login steps run only once; subsequent calls reuse the session -> Option C
  4. Quick Check:

    Session reuse = D [OK]
Quick Trick: Session callback runs once; reuse by name later [OK]
Common Mistakes:
  • Thinking login runs every time
  • Expecting error without callback on reuse
  • Assuming session clears automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes