home / skills / willsigmon / sigstack / playwright-expert

playwright-expert skill

/plugins/testing/skills/playwright-expert

This skill helps you implement Playwright end-to-end tests across browsers with auto-waiting, visual regression, and mobile emulation.

npx playbooks add skill willsigmon/sigstack --skill playwright-expert

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
2.9 KB
---
name: Playwright Expert
description: Playwright testing - cross-browser, auto-waiting, visual testing, mobile emulation
allowed-tools: Read, Edit, Bash
model: sonnet
---

# Playwright Testing Expert

Modern end-to-end testing with Playwright.

## Why Playwright
- Cross-browser (Chrome, Firefox, Safari)
- Auto-waiting (no flaky tests)
- Mobile emulation
- API testing
- Visual regression
- Trace viewer debugging

## Setup

```bash
pnpm create playwright
# or
pnpm add -D @playwright/test
npx playwright install
```

## Test Patterns

### Basic Test
```typescript
import { test, expect } from '@playwright/test';

test('user can login', async ({ page }) => {
  await page.goto('/login');

  await page.fill('[name="email"]', '[email protected]');
  await page.fill('[name="password"]', 'password');
  await page.click('button[type="submit"]');

  await expect(page).toHaveURL('/dashboard');
  await expect(page.locator('h1')).toContainText('Welcome');
});
```

### Page Object Model
```typescript
// pages/login.ts
export class LoginPage {
  constructor(private page: Page) {}

  async login(email: string, password: string) {
    await this.page.fill('[name="email"]', email);
    await this.page.fill('[name="password"]', password);
    await this.page.click('button[type="submit"]');
  }
}

// tests/auth.spec.ts
test('login flow', async ({ page }) => {
  const loginPage = new LoginPage(page);
  await page.goto('/login');
  await loginPage.login('[email protected]', 'password');
  await expect(page).toHaveURL('/dashboard');
});
```

### API Testing
```typescript
test('API health check', async ({ request }) => {
  const response = await request.get('/api/health');
  expect(response.ok()).toBeTruthy();
  expect(await response.json()).toEqual({ status: 'ok' });
});
```

### Visual Regression
```typescript
test('homepage visual', async ({ page }) => {
  await page.goto('/');
  await expect(page).toHaveScreenshot('homepage.png');
});
```

### Mobile Testing
```typescript
import { devices } from '@playwright/test';

test.use(devices['iPhone 14']);

test('mobile menu', async ({ page }) => {
  await page.goto('/');
  await page.click('[data-testid="menu-toggle"]');
  await expect(page.locator('nav')).toBeVisible();
});
```

## Configuration

```typescript
// playwright.config.ts
export default defineConfig({
  testDir: './tests',
  retries: process.env.CI ? 2 : 0,
  workers: process.env.CI ? 1 : undefined,
  reporter: 'html',
  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: 'mobile', use: { ...devices['iPhone 14'] } },
  ],
});
```

## MCP Integration
Playwright MCP server enables browser automation directly from Claude.

Use when: E2E testing, cross-browser testing, visual regression, API testing

Overview

This skill provides hands-on Playwright expertise for modern end-to-end testing across browsers, mobile emulation, API checks, and visual regression. It focuses on reliable, maintainable test patterns, configuration best practices, and orchestration for CI environments. Use it to reduce flakiness, speed up debugging, and validate UI and API behavior consistently.

How this skill works

The skill inspects and builds Playwright test suites using TypeScript patterns like basic tests and the Page Object Model, configures multi-project runs for Chromium/Firefox/Safari and mobile devices, and enables visual snapshot comparisons and API requests. It sets sensible defaults for retries, tracing, and screenshots to improve failure diagnostics. Optionally integrates with an MCP server for remote browser automation and Claude-driven orchestration.

When to use it

  • End-to-end testing of user flows including login, checkout, and dashboards.
  • Cross-browser validation across Chromium, Firefox, and WebKit (Safari).
  • Visual regression checks to detect unintended UI changes.
  • API contract and health checks alongside browser tests.
  • Mobile emulation testing for responsive layouts and touch interactions.

Best practices

  • Use auto-waiting selectors and Playwright expects to minimize flaky waits.
  • Organize tests with the Page Object Model to keep selectors and flows reusable.
  • Keep playwright.config.ts in source control with CI-friendly retries, workers, and reporters.
  • Capture traces on first retry and screenshots only on failures for efficient debugging.
  • Run focused browser projects locally, and full matrix in CI with limited workers on CI nodes.

Example use cases

  • Validate login and dashboard flows across desktop and iPhone 14 emulation.
  • Add visual snapshot tests for homepage and key components to catch regressions.
  • Write API health checks and endpoint assertions as part of E2E suites.
  • Debug flaky tests using Playwright trace viewer and on-first-retry traces.
  • Execute a CI pipeline that runs Chromium, Firefox, and mobile projects with HTML reporting.

FAQ

How do I reduce flaky tests?

Prefer playwright built-in auto-waiting, use expects for state assertions, avoid fixed sleeps, and capture traces on retry to inspect intermittent failures.

Can I test APIs with Playwright?

Yes. Use the request fixture to perform HTTP calls, assert responses, and integrate API checks with UI flows in the same test run.