Playwright pro

From seaworld008/Commonly-used-high-value-skills · View interactive version

Playwright pro is an AI agent skill from the GitHub repository seaworld008/Commonly-used-high-value-skills. Production-grade Playwright testing skill for E2E suites, flaky test diagnosis, browser automation, migration from Cypress/Selenium, CI integration, visual checks, and regression validation.

How to use this skill

Skill file

Playwright Pro

Use this skill to design, generate, review, debug, and stabilize production-grade Playwright test suites. It is the higher-discipline complement to a basic browser automation skill: focus on reliable assertions, maintainable fixtures, CI behavior, coverage strategy, and regression confidence.

When to Use

Skip When

Core Capabilities

  1. Bootstrap a maintainable Playwright configuration.
  2. Generate tests with resilient locators and web-first assertions.
  3. Design fixtures for auth, test data, API setup, and cleanup.
  4. Diagnose flakiness by timing, isolation, network, data, and selector stability.
  5. Review tests for anti-patterns and weak assertions.
  6. Migrate legacy suites while preserving behavior coverage.
  7. Integrate reports, traces, screenshots, and videos into CI.
  8. Build regression strategy around user-critical flows.

Recommended Workflow

1. Init: inspect framework, routes, auth, package manager, and test conventions.
2. Generate: write the smallest high-value tests for critical user paths.
3. Review: check locators, assertions, isolation, data setup, and failure diagnostics.
4. Run: execute locally in headless mode first, then headed for debugging if needed.
5. Stabilize: remove sleeps, isolate state, and add deterministic waits.
6. CI: shard, report, upload traces, and set retry policy.
7. Maintain: add regression tests for every escaped bug.

Project Setup Checklist

Example Config

import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  testDir: './tests/e2e',
  timeout: 30_000,
  expect: { timeout: 5_000 },
  retries: process.env.CI ? 2 : 0,
  reporter: process.env.CI ? [['blob'], ['html', { open: 'never' }]] : 'list',
  use: {
    baseURL: process.env.PLAYWRIGHT_BASE_URL ?? 'http://localhost:3000',
    trace: 'on-first-retry',
    screenshot: 'only-on-failure',
    video: 'retain-on-failure',
  },
  projects: [
    { name: 'chromium', use: { ...devices['Desktop Chrome'] } },
  ],
  webServer: process.env.CI ? undefined : {
    command: 'npm run dev',
    url: 'http://localhost:3000',
    reuseExistingServer: true,
  },
});

Test Generation Pattern

Write tests from user intent, not DOM structure.

import { test, expect } from '@playwright/test';

test('user can sign in and reach the dashboard', async ({ page }) => {
  await page.goto('/login');
  await page.getByLabel('Email').fill('demo@example.com');
  await page.getByLabel('Password').fill(process.env.E2E_DEMO_PASSWORD!);
  await page.getByRole('button', { name: 'Sign in' }).click();

  await expect(page).toHaveURL(/dashboard/);
  await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
});

Prefer getByRole, getByLabel, getByText, and getByTestId over brittle CSS selectors. Add test IDs only where accessible locators are not stable or meaningful.

Locator Rules

Assertion Rules

Flaky Test Diagnosis

Classify the failure before fixing:

Use evidence:

npx playwright test tests/e2e/login.spec.ts --trace on
npx playwright show-trace test-results/**/trace.zip
npx playwright test --headed --debug

Fixing Flakiness

Migration from Cypress or Selenium

CI Integration

- name: Install Playwright browsers
  run: npx playwright install --with-deps

- name: Run E2E tests
  run: npx playwright test

- name: Upload Playwright report
  if: always()
  uses: actions/upload-artifact@v4
  with:
    name: playwright-report
    path: playwright-report/

In larger suites, shard by CI node and keep trace artifacts for failures.

Review Checklist

Anti-Patterns

Output Format

## Test Plan
- Critical flows:
- Fixtures/data:
- Browser matrix:
- CI artifacts:

## Generated or Changed Tests
- ...

## Flake Risks
- ...

## Commands Run
- ...

Boundaries

Do not store real credentials in tests. Do not hit production systems unless the user explicitly confirms the target and safety controls. Prefer local, staging, or mocked services for repeatable automation.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.