Test Overview
This test logs into a web application using cy.session() to cache the login session. It verifies that the user is successfully logged in by checking the presence of a logout button.
This test logs into a web application using cy.session() to cache the login session. It verifies that the user is successfully logged in by checking the presence of a logout button.
describe('Login with session caching', () => { beforeEach(() => { cy.session('user-session', () => { cy.visit('/login') cy.get('#username').type('testuser') cy.get('#password').type('password123') cy.get('#login-button').click() cy.get('#logout-button').should('be.visible') }) }) it('should keep user logged in using cached session', () => { cy.visit('/dashboard') cy.get('#logout-button').should('be.visible') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test runner is ready to execute the test suite | - | PASS |
| 2 | cy.session() is called with key 'user-session' to cache login | No cached session exists yet | - | PASS |
| 3 | Browser opens and navigates to '/login' | Login page is displayed with username, password fields and login button | - | PASS |
| 4 | Finds username input field and types 'testuser' | Username field contains 'testuser' | - | PASS |
| 5 | Finds password input field and types 'password123' | Password field contains 'password123' | - | PASS |
| 6 | Finds and clicks the login button | Login form is submitted | - | PASS |
| 7 | Checks that logout button is visible to confirm login success | Dashboard page or logged-in state with logout button visible | Assert logout button is visible | PASS |
| 8 | Session 'user-session' is cached for reuse | Session data stored internally by Cypress | - | PASS |
| 9 | Test visits '/dashboard' page using cached session | Dashboard page loads without needing to login again | - | PASS |
| 10 | Checks that logout button is visible on dashboard | User is confirmed logged in on dashboard | Assert logout button is visible | PASS |