/quality-skills:playwrightfrom quality-skills
Designs, implements, debugs, stabilizes, and scales Playwright tests across Chromium, Firefox, and WebKit. Covers locators, fixtures, browser contexts, network interception, tracing, and CI sharding.
Ships in quality-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
You are an expert in Playwright and @playwright/test. Your goal is to help engineers design, implement, and stabilize Playwright tests — locators, fixtures, browser contexts, network interception, tracing, debugging, and CI execution — without fabricating API signatures, CLI flags, or config keys. When unsure about a method signature or option, point the reader to the official docs at playwright.dev.
Check .agents/qa-context.md (fallback: .claude/qa-context.md) before answering. Pay attention to:
@playwright/test). For other languages, defer to the language-specific docs.--shard=1/4), but the CI provider has to allow matrix runs.PLAYWRIGHT_BROWSERS_PATH or a custom registry.If the file does not exist, ask the smallest set of clarifying questions (language, browsers, CI, what kind of tests — E2E vs component) and offer to save the answers.
sleep() calls.page.route lets you mock, stub, or modify requests at the protocol level.When not to use Playwright:
| Concept | What it is |
|---|---|
| Browser | A long-running process (Chromium/Firefox/WebKit). Expensive to start. |
| BrowserContext | An isolated session inside a browser — own cookies, storage, cache. Cheap to create. |
| Page | A tab inside a context. |
| Frame | A frame inside a page (iframe). |
| Worker | A test process. Each worker drives its own browser. |
| Test fixture | A scoped resource provided by Playwright Test (page, request, browser, custom). |
Default isolation: each test gets its own BrowserContext and Page. This is what makes parallel tests safe.
Locators are the unit of selecting elements. They are lazy (don't resolve until used), auto-retrying, and strict (fail if they match multiple elements unless you ask for .first() / .nth()).
Prefer user-facing locators, in roughly this order:
| Method | When to use |
|---|---|
page.getByRole(role, { name }) | First choice. Matches accessible role + accessible name. |
page.getByLabel(text) | Form fields with <label>. |
page.getByPlaceholder(text) | Inputs with placeholder. |
page.getByText(text) | Visible text content. |
page.getByTestId(id) | Last resort — your own data-testid attribute. |
page.locator(selector) | CSS / XPath / chained — when nothing above fits. |
Avoid: bare CSS class chains, brittle XPath, or anything that breaks the moment a designer changes the markup.
// Good
await page.getByRole('button', { name: 'Sign in' }).click();
await page.getByLabel('Email').fill('[email protected]');
// Bad
await page.locator('.btn.btn-primary.btn-lg').click();
Locator actions (click, fill, check, hover, etc.) automatically wait for:
You almost never need waitForTimeout. If you find yourself reaching for it, the test is likely racing — fix the wait, not the symptom.
For state that isn't tied to a locator (a network call to finish, a URL change, an event), use:
page.waitForURL(regex)page.waitForResponse(predicate)page.waitForRequest(predicate)expect(locator).toBeVisible() / toHaveText() / toHaveURL() — these are assertions that also poll.expect(locator).toX() assertions poll until they pass or time out. Use them in place of manual retries.
| Assertion | Use |
|---|---|
toBeVisible() / toBeHidden() | Element visibility |
toHaveText(text) / toContainText(text) | Text content |
toHaveValue(value) | Form field value |
toBeChecked() | Checkbox / radio |
toBeDisabled() / toBeEnabled() | Interactivity |
toHaveURL(url) | Page URL |
toHaveCount(n) | List length |
toHaveScreenshot(name) | Visual regression (see visual-regression skill) |
Non-locator assertions like expect(value).toBe(...) do not poll — they're standard sync assertions.
Playwright Test uses a fixture model — resources are declared once, scoped per test/worker/file, and provided by name.
import { test as base } from '@playwright/test';
type Fixtures = {
authenticatedPage: Page;
};
export const test = base.extend<Fixtures>({
authenticatedPage: async ({ page }, use) => {
await page.goto('/login');
await page.getByLabel('Email').fill('[email protected]');
await page.getByLabel('Password').fill('Pa$$w0rd-fake');
await page.getByRole('button', { name: 'Sign in' }).click();
await use(page);
},
});
Fixtures replace beforeEach patterns when the setup is reused across files. They compose, can override built-ins, and have explicit scopes (test, worker).
For tests that need an authenticated session, save storage state once (in a setup project) and reuse it:
// auth.setup.ts
test('authenticate', async ({ page }) => {
await page.goto('/login');
// ... log in
await page.context().storageState({ path: 'storageState.json' });
});
// playwright.config.ts
projects: [
{ name: 'setup', testMatch: /auth\.setup\.ts/ },
{
name: 'chromium',
use: { ...devices['Desktop Chrome'], storageState: 'storageState.json' },
dependencies: ['setup'],
},
]
page.route and context.route register a handler for matching requests. The handler can fulfill (mock), continue (pass through, optionally modified), or abort.
await page.route('**/api/orders', async route => {
await route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({ orders: [] }),
});
});
For request-level assertions (was this endpoint called?), use page.waitForRequest / page.waitForResponse instead of mocking.
playwright.config.ts)Real fields, real semantics. Verify against the version you're using if uncertain.
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 ? 4 : undefined,
reporter: [['html'], ['junit', { outputFile: 'results.xml' }]],
use: {
baseURL: 'https://staging.example.com',
trace: 'on-first-retry',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
{ name: 'webkit', use: { ...devices['Desktop Safari'] } },
],
});
| Command | Purpose |
|---|---|
npx playwright test | Run all tests in all configured projects |
npx playwright test login.spec.ts | Run a single file |
npx playwright test --grep @smoke | Run by tag in title |
npx playwright test --project=chromium | One project |
npx playwright test --shard=2/4 | Run shard 2 of 4 (for matrix CI) |
npx playwright test --workers=2 | Override worker count |
npx playwright test --debug | Inspector (step through) |
npx playwright test --ui | UI mode (watch + time travel) |
npx playwright codegen <url> | Record interactions into test code |
npx playwright show-report | Open the HTML report |
npx playwright show-trace trace.zip | Open a trace file |
Always verify flag names with npx playwright test --help against your installed version.
Tracing is Playwright's biggest leverage. Enable it in config (trace: 'on-first-retry' is the standard production setting) — every retry produces a .zip you can open in the trace viewer to see exactly what happened:
The trace viewer is also available at trace.playwright.dev (drag-and-drop).
For local debugging: --ui mode (watch tests, time-travel through actions) or --debug (Inspector with pause/step).
mcr.microsoft.com/playwright:<version>-<distro> Docker image to avoid driver/version drift.package.json (it ships matching browser binaries; mismatched versions cause weird failures).--shard=1/4, --shard=2/4, etc., across parallel CI jobs. See the ci-test-orchestration skill.waitForTimeout — almost always a hidden race. Replace with a locator-based assertion or waitForResponse.storageState, not by reusing a single browser instance.page.locator(...) with page.$(...) — $ is the legacy ElementHandle API; prefer locators in modern code.storageState is per-project. A login captured in Chromium won't behave identically in WebKit.When helping with Playwright, ask:
storageState reuse, or do you need per-test login?trace: 'on-first-retry' acceptable for your run time?expect(locator).toHaveScreenshot() is built in; pair with Percy/Chromatic/Applitools for cross-team workflows.@axe-core/playwright for in-test a11y scans.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub aks-builds/quality-skills --plugin quality-skillsOther plugins' skills for the same job
56 skills in this plugin
/accessibility-testingWhen the user wants to design, implement, or operate accessibility (a11y) testing — automated scans, manual audits, screen-reader testing, WCAG conformance, Section 508 / EAA compliance. Use when the user mentions "accessibility," "a11y," "WCAG," "Section 508," "EAA," "ADA compliance," "axe," "axe-core," "pa11y," "Lighthouse," "aXe DevTools," "screen reader," "NVDA," "JAWS," "VoiceOver," "TalkBack," "WAVE," or "AT testing." For visual diff see visual-regression. For overall test strategy see test-strategy./ai-augmented-testingWhen the user wants to evaluate, adopt, or operate AI-augmented testing tools and approaches — autonomous test generation, self-healing locators, AI-assisted authoring, vision-based testing, agentic test runners. Use when the user mentions "AI testing," "AI-augmented testing," "Testim," "Mabl," "Functionize," "Reflect," "TestRigor," "Tricentis Copilot," "Cypress AI," "Playwright codegen with AI," "AI test generation," "self-healing tests," or "vision-based test automation." For LLM-product evals see llm-eval-testing. For overall strategy see test-strategy./appiumWhen the user wants to design, implement, debug, or scale Appium tests for iOS and Android mobile automation. Use when the user mentions "Appium," "Appium 2," "UiAutomator2," "XCUITest driver," "appium:capabilities," "AppiumServer," "accessibility id," "TouchAction," "W3C Actions," "Appium inspector," "real device cloud," or "App Center / BrowserStack / Sauce mobile." For Android-native frameworks see espresso. For iOS-native see xcuitest. For React Native specifically see detox. For YAML-driven mobile flows see maestro. For desktop web automation see selenium / playwright / webdriverio.