Test Overview
This test checks that a web page's login form works correctly by organizing assertions to verify each step clearly. It ensures the username and password fields accept input and the login button triggers the expected success message.
This test checks that a web page's login form works correctly by organizing assertions to verify each step clearly. It ensures the username and password fields accept input and the login button triggers the expected success message.
describe('Login Form Test', () => { it('should allow user to login successfully', () => { cy.visit('https://example.com/login') // Check username input cy.get('#username').should('be.visible').type('testuser') cy.get('#username').should('have.value', 'testuser') // Check password input cy.get('#password').should('be.visible').type('password123') cy.get('#password').should('have.value', 'password123') // Click login button cy.get('#loginBtn').should('be.enabled').click() // Verify success message cy.get('#successMessage').should('be.visible').and('contain.text', 'Welcome, testuser!') }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and navigates to the login page URL | Browser shows the login page with username, password fields, and login button | - | PASS |
| 2 | Finds username input field and checks it is visible | Username input field is visible on the page | Assert username input is visible | PASS |
| 3 | Types 'testuser' into username input | Username input contains 'testuser' | Assert username input value equals 'testuser' | PASS |
| 4 | Finds password input field and checks it is visible | Password input field is visible on the page | Assert password input is visible | PASS |
| 5 | Types 'password123' into password input | Password input contains 'password123' | Assert password input value equals 'password123' | PASS |
| 6 | Finds login button and checks it is enabled | Login button is enabled and clickable | Assert login button is enabled | PASS |
| 7 | Clicks the login button | Login button clicked, page processes login | - | PASS |
| 8 | Finds success message and checks it is visible with correct text | Success message 'Welcome, testuser!' is visible on the page | Assert success message contains 'Welcome, testuser!' | PASS |