Playwright E2E testing patterns, cross-browser configuration, page objects, and CI setup. Use when creating E2E specs, visual regression suites, or configuring Playwright in CI. Trigger terms: playwright, e2e, trace, page object, cross-browser
100
100%
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Advisory
Suggest reviewing before use
For project-specific test configuration and breakpoints, see testing-config.md.
npx playwright test # Run all tests
npx playwright test --ui # Open interactive UI mode
npx playwright test --headed # Run with visible browsers
npx playwright test auth.spec.ts # Run specific spec
npx playwright test --project=chromium # Run in specific browser
npx playwright test --grep "login" # Filter by test name
npx playwright test --debug # Step-through debugging
npx playwright codegen http://localhost:3000 # Generate tests from actions
npx playwright show-report # View HTML test report
npx playwright install # Install browsersTests: tests/e2e/{feature}/, page objects: tests/pages/, fixtures: tests/fixtures/.
import { test, expect } from '@playwright/test';
import { LoginPage } from '../pages/login-page';
test.describe('Login', () => {
test('submits valid credentials', async ({ page }) => {
const login = new LoginPage(page);
await login.goto();
await login.fill('user@example.com', 'password123');
await page.getByRole('button', { name: 'Sign in' }).click();
await expect(page.getByTestId('dashboard')).toBeVisible();
});
});// Mock API responses for deterministic tests
await page.route('/api/login', (route) => {
route.fulfill({ status: 200, body: JSON.stringify({ token: 'test' }) });
});Prefer semantic locators; avoid brittle CSS selectors:
page.getByRole('button', { name: 'Sign in' }) // preferred: ARIA role + accessible name
page.getByLabel('Email address') // form inputs by label
page.getByTestId('login-form') // test-id for complex containers
page.getByText('Welcome back') // visible text
page.locator('[data-state="open"]') // CSS only when no semantic alternativetest.describe.npx playwright test --ui to iterate interactively.trace: 'on-first-retry'), save an HTML report, and inspect via npx playwright show-report.npx playwright show-report shows 0 failures and that saved traces contain the failing trace id.import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: [['html'], ['list']],
use: {
baseURL: 'http://localhost:3000',
trace: 'on-first-retry',
screenshot: 'only-on-failure',
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
{ name: 'webkit', use: { ...devices['Desktop Safari'] } },
{ name: 'mobile', use: { ...devices['iPhone 14'] } },
],
webServer: {
command: 'npm run dev',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
});See REFERENCE.md for MCP tools and advanced config (moved to a referenced file).
trace: 'on-first-retry' selectively for flaky suites; attach trace IDs to failure ticketsf5c8508
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.