Test Overview
This test uses the App Actions pattern to perform a login on a sample web app. It verifies that after login, the user is redirected to the dashboard page and a welcome message is visible.
This test uses the App Actions pattern to perform a login on a sample web app. It verifies that after login, the user is redirected to the dashboard page and a welcome message is visible.
class AppActions { visitLogin() { cy.visit('/login') } fillUsername(username) { cy.get('input[name="username"]').clear().type(username) } fillPassword(password) { cy.get('input[name="password"]').clear().type(password) } submitLogin() { cy.get('button[type="submit"]').click() } login(username, password) { this.visitLogin() this.fillUsername(username) this.fillPassword(password) this.submitLogin() } verifyDashboard() { cy.url().should('include', '/dashboard') cy.get('h1').should('contain.text', 'Welcome') } } describe('Login Test using App Actions pattern', () => { const app = new AppActions() it('should login successfully and show dashboard', () => { app.login('testuser', 'Password123') app.verifyDashboard() }) })
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Cypress test runner initialized | — | PASS |
| 2 | AppActions.visitLogin() calls cy.visit('/login') | Browser navigates to /login page showing login form | — | PASS |
| 3 | AppActions.fillUsername('testuser') calls cy.get('input[name="username"]').clear().type('testuser') | Username input field is focused and filled with 'testuser' | — | PASS |
| 4 | AppActions.fillPassword('Password123') calls cy.get('input[name="password"]').clear().type('Password123') | Password input field is focused and filled with 'Password123' | — | PASS |
| 5 | AppActions.submitLogin() calls cy.get('button[type="submit"]').click() | Login form submitted, browser navigates to /dashboard page | — | PASS |
| 6 | AppActions.verifyDashboard() calls cy.url().should('include', '/dashboard') | Browser URL contains '/dashboard' | URL includes '/dashboard' | PASS |
| 7 | AppActions.verifyDashboard() calls cy.get('h1').should('contain.text', 'Welcome') | Dashboard page shows <h1> with text containing 'Welcome' | Page header contains 'Welcome' | PASS |
| 8 | Test ends | Test completed successfully | — | PASS |
App Actions pattern in Cypress tests?const addItem = (name) => { cy.get('#item-input').type(name); cy.get('#add-button').click(); }addItem('Book'); cy.get('#item-list').should('contain', 'Book');const login = (user, pass) => { cy.get('#username').type(user); cy.get('#password').type(pass); cy.get('#login-btn').click }click command is missing parentheses, so it is not called.click() to perform the click action.cy.get('#login-btn').click() -> Option AaddItem reuses existing code and ensures each item is added properly.Pass the test and this pattern moves unknown