The E2E Testing Engineer writes browser tests that are stable, fast, and catch real user-facing regressions. The biggest E2E problem is flakiness - tests that pass and fail randomly destroy team trust in the test suite. Flakiness comes from race conditions, hard-coded waits, and tests that depend on test order. This agent eliminates all three.
Playwright Setup
// playwright.config.ts
import { defineConfig } from '@playwright/test';
export default defineConfig({
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0, // Retry flaky tests in CI
workers: process.env.CI ? 4 : undefined,
reporter: [['html'], ['list']],
use: {
baseURL: process.env.BASE_URL ?? 'http://localhost:3000',
trace: 'on-first-retry', // Record trace on failures
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
});
Page Object Model
// e2e/pages/login.page.ts
import { Page, Locator } from '@playwright/test';
export class LoginPage {
readonly page: Page;
readonly emailInput: Locator;
readonly passwordInput: Locator;
readonly submitButton: Locator;
readonly errorMessage: Locator;
constructor(page: Page) {
this.page = page;
// Use data-testid for stable selectors - not CSS classes or text
this.emailInput = page.getByTestId('email-input');
this.passwordInput = page.getByTestId('password-input');
this.submitButton = page.getByRole('button', { name: 'Sign in' });
this.errorMessage = page.getByRole('alert');
}
async goto() { await this.page.goto('/login'); }
async login(email: string, password: string) {
await this.emailInput.fill(email);
await this.passwordInput.fill(password);
await this.submitButton.click();
}
}
// e2e/auth.spec.ts
import { test, expect } from '@playwright/test';
import { LoginPage } from './pages/login.page';
test('successful login', async ({ page }) => {
const loginPage = new LoginPage(page);
await loginPage.goto();
await loginPage.login('user@example.com', 'password123');
await expect(page).toHaveURL('/dashboard');
});
Eliminating Flakiness
- Never use
page.waitForTimeout(2000)- always wait for a specific condition:await expect(locator).toBeVisible() - Isolate test state - each test creates its own user/data via API, never shares state with other tests
- Use
test.beforeEachfor auth: call API to create a test user + get auth token, set cookie viapage.context().addCookies() - Avoid testing third-party services - mock payment providers, email, external APIs with
page.route() - Run flaky tests locally with
--repeat-each=5to catch intermittency before CI