0
0
Cypresstesting~10 mins

cy.session() for session caching in Cypress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start a session with the name 'userSession'.

Cypress
cy.[1]('userSession', () => {
  // login steps here
})
Drag options to blanks, or click blank then click option'
Aclick
Bvisit
Cget
Dsession
Attempts:
3 left
💡 Hint
Common Mistakes
Using cy.visit() instead of cy.session().
Forgetting to provide a session name.
2fill in blank
medium

Complete the code to restore the session named 'userSession'.

Cypress
cy.[1]('userSession')
Drag options to blanks, or click blank then click option'
Asession
Blogin
Creload
DclearCookies
Attempts:
3 left
💡 Hint
Common Mistakes
Using cy.reload() which reloads the page but does not restore session.
Using cy.clearCookies() which clears cookies instead of restoring session.
3fill in blank
hard

Fix the error in the session callback to correctly cache the login.

Cypress
cy.session('userSession', () => {
  cy.visit('/login')
  cy.get('#username').type('user')
  cy.get('#password').type('pass')
  cy.get('#submit').[1]()
})
Drag options to blanks, or click blank then click option'
Asubmit
Btype
Cclick
Dcheck
Attempts:
3 left
💡 Hint
Common Mistakes
Using type() on a button element.
Using submit() which is not a Cypress command.
Using check() which is for checkboxes.
4fill in blank
hard

Fill both blanks to create a session that caches login and validates by checking the URL.

Cypress
cy.session('userSession', () => {
  cy.visit('/login')
  cy.get('#user').type('user')
  cy.get('#pass').type('pass')
  cy.get('#loginBtn').[1]()
}, {
  validate() {
    cy.url().[2]('/dashboard')
  }
})
Drag options to blanks, or click blank then click option'
Aclick
Bshould('include')
Ccontains
Dtype
Attempts:
3 left
💡 Hint
Common Mistakes
Using type() on the login button.
Using contains instead of should('include') for URL assertion.
5fill in blank
hard

Fill all three blanks to create a session with login steps, cache key, and validation of user greeting.

Cypress
cy.session([1], () => {
  cy.visit('/login')
  cy.get('#email').type('test@example.com')
  cy.get('#password').type('password123')
  cy.get('#submitBtn').[2]()
}, {
  validate() {
    cy.get('.greeting').[3]('Welcome, test!')
  }
})
Drag options to blanks, or click blank then click option'
A'testSession'
Bclick
Cshould('contain.text')
Dtype
Attempts:
3 left
💡 Hint
Common Mistakes
Using type() on the submit button.
Using should('include') instead of should('contain.text') for greeting.
Forgetting quotes around the session name.