GuidesZero flaky tests
Test steps as natural language
Write volatile UI steps as natural language with Playwright Intent so a live browser agent handles UI churn without hiding real application bugs.
A well-described action often says more than raw Playwright code. In real end-to-end suites, plenty of things shift as a product evolves: flows get refined, markup moves around, and small adjustments are needed to keep tests aligned with how the app works today.
When tests describe clear intent instead of only low-level browser mechanics, a live agent can dynamically resolve the majority of those smaller adjustments before they ever reach human review. That makes a test suite feel much more self-managing, without forcing you to immediately relinquish control to opaque, fully agent-based testing.
Playwright Intent lets you adopt this incrementally: you write volatile UI steps in natural language (ai.do(...)), and it compiles them into cached, reviewable Playwright TypeScript that runs deterministically every day.


Delegate step mechanics to AI, keep Playwright reviewable
With Playwright Intent, your spec states what the user is trying to accomplish, while the low-level clicks and locators live in generated .intent/ TypeScript files.
On normal runs, no model runs at all: Playwright executes the cached TypeScript file directly, at normal Playwright speed, with real source lines in traces and replays. The agent only wakes up when a step has never been generated yet or when a cached step fails during a run.
Hover or click the ai.do(...) call in this BikeBook checkout test to inspect the generated TypeScript file behind it:
import { expect, testWithNewUser } from "../../support/fixtures"; testWithNewUser.describe("upgrading", () => { // Programmatic user created via API in milliseconds, // isolated to this test and deleted automatically afterward. testWithNewUser( "upgrading to Plus records exactly one payment", async ({ page, ai }) => { await page.goto("/pricing"); await expect(page).toHaveURL("/dashboard/team?payment=success"); const payments = await (await page.request.get("/api/payment")).json(); expect(payments).toHaveLength(1); expect(payments[0]).toMatchObject({ planName: "Plus", amount: 1200, currency: "USD", }); }, );});Notice how the test is split:
ai.do(...)owns the multi-step UI mechanics: clicking the plan button, filling nine checkout form fields, and submitting the purchase.- Hand-written
expect(...)lines own the product contract: verifying the redirect URL and checking/api/paymentfor the exact plan name, amount, and currency.
Inside a failing step: an agent with the live browser
What makes Playwright Intent different from an offline script or a black-box AI runner is where the agent runs. When a cached step fails (and updates are enabled), Playwright does not tear down the browser first. The agent steps in inside the active test attempt with live access to the open page, checks what actually happened, and decides whether the step drifted or the application is genuinely broken:


Why live repair stays honest on real application bugs
The sharpest skepticism engineers have about "self-healing" tests is justified: what stops an agent from working around a real bug just to make CI turn green?
Playwright Intent enforces three guardrails directly in code:
- Legitimate UI changes repair cleanly; real regressions fail loudly. In BikeBook, compare
demo/pricing-flow-change(where the Plus plan is intentionally renamed to Pro at $15) againstdemo/checkout-regression(whereprocessPaymentbreaks because it looks up lowercase"plus"). On the UI rename, the agent sees the working flow in the live browser and updates the step. On the broken checkout, the agent sees the real application error on the page, leaves the cached step untouched, and returnsfailwith a diagnosis. - Dirty-page repairs must prove themselves from scratch. Playwright Intent compares the page's ARIA snapshot before and after the failed step. A repair can only continue in the same attempt when the page is still unchanged. If the failed step already mutated page state, the agent saves or clears the step, fails the current attempt, and forces Playwright's clean retry to prove the new step end to end.
- Your spec assertions stay untouchable. Hand-written
expect(...)calls in your.spec.tsfile (like checking/api/paymentabove) are never edited by the agent.
A green replay alone still does not guarantee an agent never wrote an overly defensive if (isVisible()) check inside a generated step. That is why starting with reviewable Git diffs is the right first step before granting higher autonomy.
The four-stage trust ladder
You do not have to hand over your test suite on day one. Playwright Intent lets you start with plain Git-reviewed files and step up autonomy only as your team builds trust in how it behaves on your app.
Stage 1: Git-committed steps, zero CI model calls (ci: refuse())
Start here. Generate .intent/ files locally while writing tests, review them in pull requests just like hand-written TypeScript, and lock CI to refuse() so pull request checks never call a model:
import { fileStore, allow, refuse } from "playwright-intent/file-store";
export const intent = {
store: fileStore({
updates: {
local: allow(),
ci: refuse(),
},
}),
};During your first few PR reviews, check generated steps for the same standards you expect from teammates: clean semantic locators, a real closing assertion, and no waitForTimeout or defensive if (isVisible()) workarounds.
Stage 2: CI proposes reviewable diffs on pull requests (ci: propose())
Once local generation feels solid, switch ci: refuse() to ci: propose() (and add playwright-intent/reporter plus retries: 1). When a pull request changes the UI and breaks a cached step, CI diagnoses and proves the fix on a retry, posts a pull request comment with a reviewable git diff patch, and keeps the check red until a human applies it.
This is the best proving ground: you get to watch the agent repair legitimate UI changes while verifying it still fails loudly on real bugs.
Stage 3: CI commits verified repairs to the PR (ci: commit())
When proposed patches consistently look right, switch propose() to commit(). Verified step updates land as a single commit directly on the pull request branch so the PR stays green and every change remains visible in Git history and code review.
Stage 4: Remote store with no .intent/ files in Git (remoteStore)
Once your team has earned full confidence in step quality and no longer wants .intent/ files tracked in Git, move to remoteStore backed by @playwright-intent/cache-api on S3-compatible storage (such as Cloudflare R2):
import { remoteStore, shared } from "playwright-intent/remote-store";
export const intent = {
store: remoteStore({
url: process.env.PLAYWRIGHT_INTENT_CACHE_URL!,
token: process.env.PLAYWRIGHT_INTENT_CACHE_TOKEN!,
updates: shared(),
}),
};CI downloads cached steps before tests run and uploads verified repairs afterward without touching Git. The trade-off is clear: zero .intent/ diffs in pull requests, in exchange for giving up per-PR Git review of step code (and noting that shared() currently uses last-write-wins across branches).
| Stage | Where steps live | CI model calls | How updates land | When to use it |
|---|---|---|---|---|
1. ci: refuse() | Git (.intent/) | None | Generated locally and committed in PRs | Every team's starting point |
2. ci: propose() | Git (.intent/) | Only on broken steps | Posted as a PR comment diff; check stays red | Proving repair quality before granting write access |
3. ci: commit() | Git (.intent/) | Only on broken steps | Committed to the PR branch for review | Fast UI iteration with full Git auditability |
4. remoteStore | Remote cache API | Only on broken steps | Uploaded to shared store automatically | High-trust teams that want .intent/ out of Git |
Next steps
Install and initialize Playwright Intent in your existing Playwright suite.
Stores and updatesFull configuration reference for fileStore, propose(), commit(), and remoteStore.
The no-flake strategySee how natural-language steps pair with weekly flake fixing and on-demand PR triage.
Last updated