/playwright-automation:fix-flaky-testsfrom playwright-automation
This skill should be used when a Playwright test is failing, flaky, timing out, or behaving inconsistently. It provides structured root cause analysis for: stabilizing intermittent tests, debugging timeouts ("Test timeout of 30000ms exceeded"), fixing race conditions, investigating local-vs-CI divergence, running repeated stability checks (--repeat-each). IMPORTANT: If running tests with --repeat-each, --retries, or multiple times to check stability, STOP and load this skill first — it has structured root cause analysis that prevents brute-force approaches. Triggers: "stabilize", "intermittent", "flaky", "keeps failing", "fails in CI", "timeout on", "race condition", "run N times to check stability", "verify tests are stable". NOT for writing new tests (use write-test-code) or analyzing setup (use analyze-test-codebase).
Ships in playwright-automation. 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.
Systematically diagnose and fix intermittent Playwright test failures using root cause analysis. A flaky test is worse than no test — it trains teams to ignore failures.
Parse the test file path or test name from: $ARGUMENTS
If no argument provided, ask: "Which test file or test name is flaky?"
npx playwright test <file> --repeat-each=5 --reporter=list 2>&1
npx playwright test --reporter=list 2>&1
| Category | Symptoms |
|---|---|
| Timing | Timeout errors, "element not found", "not visible yet" |
| State leakage | Passes alone, fails when run with other tests |
| Data dependency | Fails when expected data doesn't exist or has changed |
| Race condition | Action fires before page is ready (hydration, animation) |
| Selector fragility | Element found but wrong one, or .first() picks different element |
| Environment | Passes locally, fails in CI (viewport, speed, resources) |
| Evidence gap | Current DOM, viewport, or label behavior no longer matches exploration, so the next fix would be guesswork |
Investigate based on the classification:
Timing issues:
waitForResponsewaitForTimeout being used as a "fix" — this is a symptom, not a curewaitForResponse, a URL/assertion change, a loading indicator disappearing, or a hydration marker becoming readyState leakage:
npx playwright test --grep "<test name>"afterEach/afterAllstorageState bleeds between tests or test filesRace conditions:
Selector fragility:
.first() or .nth() is a smellfind and get_elementEnvironment issues:
Evidence gaps:
{ force: true }, JavaScript-dispatched clicks, coordinate clicks, page-wide text oracles, or broad CSS fallbacks because semantic selection failedUse the right fix pattern for the diagnosed root cause. Never apply a fix without understanding the cause. See references/fix-patterns.md for full code examples.
| Category | Principle |
|---|---|
| Timing | Replace sleeps with event-driven waits (waitForResponse, auto-retrying assertions) |
| State isolation | Unique data per test, API-based reset in beforeEach, no shared mutable state |
| Race condition | Use Promise.all for action + expected response; wait for hydration before interaction |
| Selector | Scope locators to containers with unique content; avoid .first() and position-dependent selectors |
| Environment | Explicit viewport, timezone-agnostic assertions, block interfering third-party scripts |
| Evidence gap | Refresh exploration/browser evidence first; do not guess with workaround-heavy code changes |
Evidence-sensitive workarounds are not normal fixes. Treat these as last-resort options that require fresh browser evidence or explicit reviewer/operator acceptance:
{ force: true }npx playwright test <file> --repeat-each=5 --reporter=list 2>&1
npx playwright test --reporter=list 2>&1
Report:
When the standard categories don't fit, check these:
These mask the problem. Never apply them without a real fix:
| "Fix" | Why It's Wrong | Real Fix |
|---|---|---|
waitForTimeout(3000) | Hides timing race, will break under load | Wait for the specific event |
.first() added | Hides selector ambiguity | Narrow the selector |
| Increased timeout to 30s | Hides missing wait or slow setup | Find what you're actually waiting for |
test.skip() | Ignoring the problem | Diagnose and fix |
retries: 3 without fix | Masks real failures, wastes CI time | Fix the root cause, then keep retries as safety net |
{ force: true } | Bypasses actionability checks, hides overlapping elements or disabled state | Find and fix the actionability issue: wait for overlay to disappear, scroll element into view, or wait for enabled state |
locator.evaluate(() => el.click()) / JS click | Bypasses the browser's real interaction model and can hide overlay, timing, or disabled-state issues | Re-explore the live DOM and restore a real user interaction path |
| Coordinate click from a guessed box | Couples the test to one viewport and guessed geometry | Re-explore at the execution viewport and find a stable selector or justified coordinate contract |
| Page-wide text oracle | Confuses incidental render text with the intended control state | Scope the assertion to the control/container proved by fresh evidence |
try/catch swallowing errors | Test passes but doesn't verify anything | Fix the assertion |
When a suite has several flaky tests:
beforeEach, a leaking storageState, or a missing cleanup can cause many tests to fail. One fix resolves many failures.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub lespaceman/athena-workflow-marketplace --plugin playwright-automation5 skills in this plugin
/add-playwright-testsTHE DEFAULT ENTRY POINT for the Playwright execution layer in the split testing suite. Use to add, create, or set up Playwright end-to-end tests for a feature, page, or application. It orchestrates the full Playwright workflow after shared exploration and planning: analyze the Playwright codebase, consume `docs/qa/feature-map.md`, `docs/qa/exploration-report.md`, `docs/qa/coverage-plan.md`, and `docs/qa/test-cases/*.md`, write production-grade test code, review it, and verify it with real execution. Delegates to `analyze-test-codebase`, `write-test-code`, `review-test-code`, and `fix-flaky-tests`, while relying on shared `map-feature-scope`, `capture-feature-evidence`, `plan-test-coverage`, `generate-test-cases`, and `review-test-cases`.
/analyze-test-codebaseScans and reports on an existing Playwright test codebase. This skill should be used to inspect the current Playwright setup before writing, reviewing, or fixing tests, and should be loaded early when working in a new project to understand existing patterns. Covers: Playwright config, page objects, fixtures, helpers, auth/globalSetup patterns, test conventions, and directory structure. Triggers: "understand", "check", "show me", "inspect", or "analyze" the current test setup, config, infrastructure, patterns, or conventions. In the full add-tests workflow, this skill serves as an early read-only analysis sub-step before planning detailed coverage or writing code. This skill examines existing files and outputs a structured report. It does NOT write or fix tests, install Playwright, or explore live websites — for live-site exploration, use `capture-feature-evidence` so evidence is captured in `docs/qa/exploration-report.md`.
/review-test-codeQuality review of Playwright test code before final execution signoff. This skill should be used when implementation review of executable Playwright tests is needed, not for diagnosis of runtime flakiness. Triggers: "review test code", "review Playwright tests", "check test quality", "audit test implementation", "review my tests before merging", "check test code for issues", "review e2e tests", "code review Playwright", "are my tests stable", "check for brittle selectors", "review before running tests". Quality gate after write-test-code — catches brittle selectors, force:true misuse, networkidle overuse, Tailwind utility class selectors, exact numeric assertions, missing teardown, parallel-unsafe mutations, hardcoded data, missing assertions, test coupling, and convention divergence. Review-only — does NOT rewrite tests, does NOT run tests. Use fix-flaky-tests for fixing, write-test-code for rewriting.
/write-test-codeThis skill should be used when writing, refactoring, or modifying Playwright E2E test code. It covers creating test files from TC-ID specs, converting browser exploration results to executable tests, refactoring locators or fixtures, adding API mocking, test data setup/teardown, and parallel-safe isolation. Includes locator strategy hierarchy, auth setup patterns, fixture design, teardown strategies, and network interception recipes. Triggers: "write a test for", "add a test case", "refactor this locator", "add error path tests", "convert specs to code", "add API mocking", "set up auth for tests". NOT for: full pipeline from scratch (use add-playwright-tests), shared live-site exploration (use capture-feature-evidence), generating specs without code (use plan-test-coverage or generate-test-cases), diagnosing flaky tests (use fix-flaky-tests).