0
0
Cypresstesting~10 mins

Page Object Model in Cypress - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test uses the Page Object Model to separate page structure from test logic. It verifies that a user can log in successfully and see a welcome message.

Test Code - Cypress
Cypress
class LoginPage {
  visit() {
    cy.visit('https://example.com/login')
  }

  fillUsername(name) {
    cy.get('#username').clear().type(name)
  }

  fillPassword(password) {
    cy.get('#password').clear().type(password)
  }

  submit() {
    cy.get('button[type="submit"]').click()
  }
}

describe('Login Test with POM', () => {
  const loginPage = new LoginPage()

  it('should log in successfully and show welcome message', () => {
    loginPage.visit()
    loginPage.fillUsername('testuser')
    loginPage.fillPassword('Password123')
    loginPage.submit()
    cy.get('#welcome-message').should('contain.text', 'Welcome, testuser!')
  })
})
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test startsCypress test runner initialized-PASS
2Browser opens and navigates to 'https://example.com/login'Login page is displayed with username and password fieldsURL is 'https://example.com/login'PASS
3Finds username input field with selector '#username' and types 'testuser'Username field contains 'testuser'Username input value is 'testuser'PASS
4Finds password input field with selector '#password' and types 'Password123'Password field contains 'Password123'Password input value is 'Password123'PASS
5Finds submit button with selector 'button[type="submit"]' and clicks itForm submitted, page processes login-PASS
6Finds element with selector '#welcome-message' and checks it contains text 'Welcome, testuser!'Welcome message is visible on the pageText content includes 'Welcome, testuser!'PASS
7Test endsTest completed successfully-PASS
Failure Scenario
Failing Condition: Welcome message element '#welcome-message' is not found or text does not match
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after submitting the login form?
AThat the welcome message contains the username
BThat the login page reloads
CThat the password field is cleared
DThat the submit button is disabled
Key Result
Using the Page Object Model helps keep tests clean and easy to maintain by separating page details from test steps.