Skip to main content

E2E Testing

Folder: .github/skills/tsh-e2e-testing/
Used by: E2E Engineer

Provides Playwright-specific E2E testing patterns, Page Object conventions, mocking strategies, error recovery, and CI readiness checklists.

Page Object Pattern

export class LoginPage {
constructor(private page: Page) {}

async navigateTo() {
await this.page.goto('/login');
}

async fillCredentials(email: string, password: string) {
await this.page.getByLabel('Email').fill(email);
await this.page.getByLabel('Password').fill(password);
}

async submit() {
await this.page.getByRole('button', { name: 'Sign in' }).click();
}
}

Test Structure

Tests follow the Arrange → Act → Assert pattern with should [behavior] when [condition] naming.

Verification Loop

LimitValue
Max iterations per test5
Max iterations per suite15
Consecutive passes required3

Error Recovery

Error TypeRecovery Strategy
TimeoutIncrease timeout, check for lazy loading
Element not foundVerify locator, check if element is conditional
NetworkCheck dev server, verify API mocking
FlakyAdd explicit waits for UI elements, not timers
App bugMark test.fixme(), report to SE

Mocking Rules

  • Mock external APIs only — never mock the application under test.
  • Use Playwright's page.route() for API interception.

CI Readiness Checklist

  • All tests pass in headless mode.
  • BASE_URL configured via environment variable.
  • No hardcoded credentials.
  • Explicit viewport size set.

Quick Reference

AlwaysNever
Use getByRole, getByLabel, getByTextUse CSS class selectors
Wait for specific UI elementsUse waitForTimeout()
Generate unique test dataDepend on state from other tests
Use environment variables for credentialsHardcode passwords