Last Updated: 2026-05-30
Purpose: Run a guided, signal-driven loop that drives a feature in Playwright, classifies every failure signal, and fixes the test (or surfaces a real bug) until the run is green.
What it is
Browser auto-heal is an agent-driven loop that wraps Playwright with a structured fix-to-green workflow. Each attempt runs your E2E target, collects test assertions, console errors, uncaught page errors, and network responses with status>= 400, then classifies the failures so the agent can apply the right fix.
Use it when you want a single command that:
- Reproduces an E2E failure on demand.
- Distinguishes locator drift, flakes, and real bugs.
- Stops automatically on spec drift or backend regressions instead of silently “fixing” them.
- Leaves a committed Playwright regression test behind on success.
When to use it
- TDD green step. After a unit test passes, verify the feature in the browser before moving on.
- Spec completion gate. Run the journey clean before marking a spec complete.
- Flaky test triage. A test passes locally but fails in CI — let the loop classify the signal.
- Pre-merge confidence. Re-run a critical core (
cl,pm,hr, etc.) end-to-end after a refactor.
How the loop works
Each attempt is a single Playwright run plus a verdict:- Run one attempt. The verdict CLI invokes Playwright, writes
playwright-report/heal-signals.json, printsHEAL_VERDICT=<value>, and exits with a status code:0— green2— needs-fix3— structural-stop (spec drift or backend regression)4— retry-exhausted
- Read the verdict.
green— stop. The Playwright journey is your regression test; make sure it is committed.structural-stop— stop. ASPEC_DRIFTorBACKEND_REGRESSIONwas detected. The loop writes aheal-report.mdwith the signal, the diagnosis, and the recommended human action. Do not auto-fix.retry-exhausted— stop. Aheal-report.mdis written with the remaining signals.needs-fix— continue.
- Diagnose and fix by class. Each failure is classified:
LOCATOR_DRIFT— update the selector in the spec to match the current UI.FLAKE— replace fixed waits with web-first assertions orexpect.poll; fix the race.REAL_BUG— fix the application code. The console error, 4xx, or assertion is a true defect.- Ambiguous (passes but looks wrong, console error with no stack) — escalate to a live Playwright MCP browser session to reproduce and confirm root cause before editing.
- Re-run with the next attempt number. Repeat until
green,structural-stop, orretry-exhausted(default cap: 4 attempts).
Running the loop
The agent-driven entry point is the/heal-e2e command. It resolves a target, drives the loop, and applies fixes per class.
To drive a single attempt yourself — for example, to inspect the signals without the agent loop — use the verdict CLI directly:
playwright-report/heal-signals.json to inspect the raw signals it captured.
Example: heal a flaky CL journey
needs-fix with a LOCATOR_DRIFT classification, update the selector in the spec and re-run with --attempt 2. If the verdict is structural-stop, open the generated heal-report.md and follow the recommended action.
Guardrails
- No auto-merge. A human reviews the final diff.
- No auto-edit on structural signals.
SPEC_DRIFTandBACKEND_REGRESSIONalways surface to a human. - Retry cap. Default is 4 attempts per loop; the loop stops cleanly when exhausted.
- Server reuse. The loop reuses an existing preview server when available instead of starting a second build.
- No PHI in signals.
heal-signals.jsonrecords network paths and status codes only — never request or response bodies.
Related
- Testing setup and run — environment, Playwright install, and per-core scripts.
- Testing setup and run §9 (AI / interactive browser testing) — credentials and login flow for browser-driven tests.
- E2E test scenarios — critical user journeys covered by E2E.