Complete the code to start a session with the name 'userSession'.
cy.[1]('userSession', () => { // login steps here })
cy.visit() instead of cy.session().The cy.session() command creates a session cache with the given name.
Complete the code to restore the session named 'userSession'.
cy.[1]('userSession')
cy.reload() which reloads the page but does not restore session.cy.clearCookies() which clears cookies instead of restoring session.cy.session('userSession') restores the cached session named 'userSession'.
Fix the error in the session callback to correctly cache the login.
cy.session('userSession', () => { cy.visit('/login') cy.get('#username').type('user') cy.get('#password').type('pass') cy.get('#submit').[1]() })
type() on a button element.submit() which is not a Cypress command.check() which is for checkboxes.The click() command triggers the login button to submit the form.
Fill both blanks to create a session that caches login and validates by checking the URL.
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') } })
type() on the login button.contains instead of should('include') for URL assertion.The login button is clicked with click(). The validate callback checks the URL includes '/dashboard' using should('include').
Fill all three blanks to create a session with login steps, cache key, and validation of user greeting.
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!') } })
type() on the submit button.should('include') instead of should('contain.text') for greeting.The session name is 'testSession'. The submit button is clicked with click(). The greeting text is asserted with should('contain.text').