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.

Before and after Playwright Intent: without Playwright Intent, small product shifts break brittle locators and turn into manual PR chores where an engineer reads the trace, edits the spec, and re-runs CI. With Playwright Intent, when a cached .intent/ step fails, a live agent runs inside the active test with access to the browser, verifies the adjusted step, and saves updated .intent/ code. Normal runs skip the agent and run cached .intent/ TypeScript directly.

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:

tests/signed-in/checkout.spec.ts
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/payment for 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:

Three-step left-to-right flow inside an active Playwright test attempt: 1. Cached .intent/ step fails while the browser stays open on the current page; 2. Live agent steps in, reads the intent, old code, and error, and inspects the open page (DOM, ARIA tree, screenshot, session) via look() and run(); 3a. If the app works and the step drifted, update the cached .intent/ step and verify on a clean retry if the page changed; 3b. If it is a real app bug, leave the cached step untouched and fail loudly with a diagnosis.

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:

  1. 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) against demo/checkout-regression (where processPayment breaks 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 returns fail with a diagnosis.
  2. 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.
  3. Your spec assertions stay untouchable. Hand-written expect(...) calls in your .spec.ts file (like checking /api/payment above) 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:

playwright.config.ts (excerpt)
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):

playwright.config.ts (excerpt)
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).

StageWhere steps liveCI model callsHow updates landWhen to use it
1. ci: refuse()Git (.intent/)NoneGenerated locally and committed in PRsEvery team's starting point
2. ci: propose()Git (.intent/)Only on broken stepsPosted as a PR comment diff; check stays redProving repair quality before granting write access
3. ci: commit()Git (.intent/)Only on broken stepsCommitted to the PR branch for reviewFast UI iteration with full Git auditability
4. remoteStoreRemote cache APIOnly on broken stepsUploaded to shared store automaticallyHigh-trust teams that want .intent/ out of Git

Next steps

Last updated