0
0
Cypresstesting~10 mins

App Actions pattern in Cypress - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - Cypress
Cypress
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()
  })
})
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test startsCypress test runner initialized-PASS
2AppActions.visitLogin() calls cy.visit('/login')Browser navigates to /login page showing login form-PASS
3AppActions.fillUsername('testuser') calls cy.get('input[name="username"]').clear().type('testuser')Username input field is focused and filled with 'testuser'-PASS
4AppActions.fillPassword('Password123') calls cy.get('input[name="password"]').clear().type('Password123')Password input field is focused and filled with 'Password123'-PASS
5AppActions.submitLogin() calls cy.get('button[type="submit"]').click()Login form submitted, browser navigates to /dashboard page-PASS
6AppActions.verifyDashboard() calls cy.url().should('include', '/dashboard')Browser URL contains '/dashboard'URL includes '/dashboard'PASS
7AppActions.verifyDashboard() calls cy.get('h1').should('contain.text', 'Welcome')Dashboard page shows <h1> with text containing 'Welcome'Page header contains 'Welcome'PASS
8Test endsTest completed successfully-PASS
Failure Scenario
Failing Condition: Login button is not found or login fails causing no redirect to /dashboard
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after submitting the login form?
AThat the URL includes '/dashboard' and a welcome message is shown
BThat the login form fields are cleared
CThat the login button is disabled
DThat the username input is focused
Key Result
Using the App Actions pattern helps organize test steps into reusable methods that represent user actions, making tests easier to read and maintain.