Blog / Playwright AI Testing: Who Checks the Work When a Model Writes the Test?
Guide

Playwright AI Testing: Who Checks the Work When a Model Writes the Test?

Playwright AI covers three layers, and one can turn a real bug into a skipped test. See what AI-written scripts, MCP and test agents take on and leave you.

Playwright AI is any setup where a large language model (LLM), the kind of AI model behind most coding assistants, does part of the work Playwright used to leave to a person, such as writing the test, driving the browser or repairing the test after it fails. In 2026 the phrase covers three different layers, and Playwright now ships two of them itself.

Each layer takes one job off your plate and leaves another one on it. By the end you’ll know which layer fits your suite, and what you own after you turn it on.

What you’ll learn

  • The three things people mean by Playwright AI
  • Why an AI-written spec reaches for fixed waits, and the fix
  • How the planner, generator and healer agents hand work to each other
  • The one healer output you should never merge unread

AI Writes the Script

The oldest layer needs no Playwright feature at all. You paste a user story into a coding assistant and it hands back a .spec.ts file. It is quick, but the model has never seen your app, so it has to guess what the element is called and how long the page takes.

Those guesses show up as CSS selectors and fixed sleeps. Playwright’s own API reference marks page.waitForTimeout as discouraged and says “Tests that wait for time are inherently flaky.” The same model, asked to follow Playwright’s best practices, writes the second version below.

// What a model writes before it has seen the page
await page.click('#root > div.form > button.btn-primary');
await page.waitForTimeout(3000);
expect(await page.textContent('.toast')).toBe('Saved');

// What Playwright recommends: user-facing locators, assertions that wait
await page.getByRole('button', { name: 'Save' }).click();
await expect(page.getByRole('status')).toHaveText('Saved');

The loop back to the model is built in. Since version 1.51 the HTML report, trace viewer and UI mode carry a “Copy prompt” button on errors, which packs the error and its context into a prompt you paste into your assistant (release notes).

Playwright HTML report of a failed test, with the Copy prompt button
Playwright’s HTML report on a failed test, with Copy prompt at the top right.

TLDR: this layer saves typing. You still own every locator, every wait and the question of whether the assertion checks anything a user cares about.

An Agent Drives the Browser Through MCP

The Model Context Protocol (MCP) is an open standard for giving an AI model tools it can call. Plug in the Playwright MCP server and a model can open pages, click, type and read what came back. Since version 1.62 the server ships inside Playwright and starts with npx playwright mcp.

Playwright MCP hands the model the page’s accessibility tree instead of pixels. The tree is a list of roles and names with a reference on each element, and the model acts on those references.

- heading "todos" [level=1]
- textbox "What needs to be done?" [ref=e5]
- listitem:
  - checkbox "Toggle Todo" [ref=e10]

Split the failures in two before you blame the model. Is the element badly described in the tree, or did the model pick the wrong one? On Playwright 1.65.1, a div with a click handler and a pointer cursor shows up as generic [cursor=pointer] with its text and a reference, so the model can click it but has no role to say what it does. An empty div with no text and no pointer cursor can drop out of the snapshot altogether.

We built Pie’s web agent to look at the screen first for the same reason. Few teams keep their selector and accessibility IDs clean.

Two defaults deserve a look before you point an agent at a staging app:

  • State carries over. The default profile is persistent, so login state and cookies survive between sessions. Pass --isolated when each session should start clean.
  • One tool runs arbitrary code. The docs call browser_run_code_unsafe “RCE-equivalent”, meaning as risky as remote code execution (RCE), and say to enable it only for trusted clients.
{
  "mcpServers": {
    "playwright": {
      "command": "npx",
      "args": ["playwright", "mcp", "--isolated", "--headless"]
    }
  }
}

An agent session is not a test, either. When the chat ends, nothing reruns tomorrow unless the agent saved a spec file.

Playwright Test Agents: Plan, Generate, Heal

Version 1.56 added the third layer, Playwright Test Agents, three agent definitions that guide a model through building a test. One command writes them into your repo, with a flag for the client you use.

npx playwright init-agents --loop=claude   # or vscode, codex, opencode
AgentTakesReturns
PlannerA request, a seed test, optionally a PRDA Markdown test plan in specs/, with steps and expected results
GeneratorThe Markdown planSpec files in tests/, with selectors and assertions checked live against the app
HealerThe name of a failing testA passing test, or a skipped test if it believes the feature is broken

The seed test carries more weight than its name suggests. The planner runs it first to get your global setup, fixtures and login, and copies its style into every generated test. A thin seed gives you thin tests.

The generator fixes the first layer’s main flaw, because it checks each selector against the running app instead of guessing. Upgrade Playwright and regenerate the definitions too, since the docs say they pick up new tools and instructions with each release. Wiring these agents into a full pipeline adds orchestration and a model bill per run, the costs our guide to agentic test automation counts up.

What Each Layer Leaves to You

All three are AI testing in the first sense of the phrase, meaning AI-powered tools that test software rather than tests for an AI model. They differ in the job they take and the one they hand back.

LayerTakes off your plateLeaves to youFailure to watch for
AI writes the scriptTyping the first draftLocators, waits and what the assertion provesFixed sleeps that pass locally and flake in CI
Agent over MCPClicking through a flow by handSaving a repeatable test, session state, tool permissionsClickable divs with no role, which the agent has to guess at
Test agentsPlan, first spec and locator repairsThe seed test, the expected results, review of every healA real bug turned into a skipped test

One job appears in rows 1 and 3 and never leaves, and it is deciding what correct looks like. Testers call that the oracle. A model can write steps in seconds, and it can’t know that “Saved” should have said “Published” unless a plan or a person told it.

Where Self-Healing Stops

The healer replays the failing test and inspects the page where it broke. Then it patches the test and reruns it, in a loop that Playwright says runs “until it passes or until guardrails stop the loop”. The docs give locator updates, wait adjustments and data fixes as examples of its patches.

The agent file that init-agents writes into your repo goes further. As of Playwright 1.65.1, its instructions list “assertions and expected values” among the things to fix, and one line sets the tone for every heal:

“Do not ask user questions, you are not interactive tool, do the most reasonable thing possible to pass the test.”
playwright-test-healer.md, written by npx playwright init-agents

When the error persists and the model is confident the test is correct, it marks the test test.fixme() and leaves a comment on the failing step. The next run skips that test, and the build goes green.

Before you let it run, sort failures into two kinds:

  1. The page changed and the feature didn’t. A button was renamed or moved. A new locator is the right fix, and the healer is good at it.
  2. The feature changed. The total is wrong, or the confirmation never shows. No locator fixes that. The healer either rewrites the expected value to match the bug or parks the test as fixme.

Both outcomes are decisions about your product, made by a model, in a diff that looks like test maintenance. So route heals the way you route code:

  • Open each heal as its own pull request, with the trace attached.
  • Flag any heal that changes an expected value, and fail CI on any new test.fixme until a person approves it.
  • Run with --fail-on-flaky-tests once the suite is stable, so a retry can’t hide a flaky heal.

Commercial self-healing test automation tools make the same trade at a different point. They repair the locator at run time, and the same question about behavior stays with you.

Does AI Change Playwright vs Cypress?

Less than you might expect. Cypress has its own AI command, cy.prompt, which turns plain-English steps into Cypress commands inside the test. It arrived in Cypress 15.4.0 and moved to beta in 15.13.0.

Playwright Test AgentsCypress cy.prompt
Where the AI livesAgent files in your repo, run by your AI clientA command inside the test file
Account neededYour AI client’sA Cypress Cloud account or record key
BrowsersPlaywright’s Chromium, Firefox and WebKitChromium-based browsers

Cypress has a real edge here. The natural-language steps stay in the test, so a reader sees intent next to the code. Playwright’s edge is that the agents are open definitions you can read, edit and run with the model you already pay for. Neither flips the underlying Playwright vs Cypress choice, which turns on browsers, language support and how each runner handles tabs and parallel runs.

Tests With No Script Underneath

Every layer above ends in a Playwright script your team owns. The model writes it, repairs it or drives the browser that produced it, and the script is the thing that breaks.

Pie takes the script out of that loop. It is AI-native, not a model added to a script runner, so your team has no Playwright file to own. Our agentic testing platform explores your app, and each flow it reaches becomes a test written as plain steps a person can read, from opening the cart to applying the code and checking the total.

  • No scripts to write, no locators to break. On the web Pie looks at the screen first and uses page locators where they are more reliable, and your team never writes or repairs them.
  • Every run re-reads the screen. Tests are written to survive layout changes, and nothing edits your test on its own.
  • One place for web and mobile. Web apps run in a browser, and iOS and Android apps run on simulators and emulators, with real devices available on demand.

Pick the Layer by the Job You Want Gone

Name the job you want gone first. If it is typing tests, let a model write them and fix the waits. If it is clicking through flows, give an agent Playwright MCP with --isolated. If it is keeping a suite alive, add the test agents and gate every heal on a person reading the skip.

See Your Flows Tested Without a Script

Bring a staging URL and watch Pie explore it and run the flows it finds.

Frequently Asked Questions

No. Playwright is Microsoft's open-source framework for automating browsers, and it runs tests the same way with or without AI. Recent versions add optional AI pieces, such as test agents and a Model Context Protocol (MCP) server, but the AI model comes from the assistant you connect.
It is Playwright with an AI model doing work a person used to do. The model can write the test script, drive the browser through Playwright's MCP server, or plan and repair tests with the built-in agents. Playwright still runs every test, so results are as repeatable as the script.
No. Playwright MCP is a server that lets an AI assistant open pages, click and read results in a real browser. The test agents are instruction files that use those browser tools to plan tests, write the spec files and repair tests that fail.
Playwright's docs name four assistants, which are VS Code, Claude Code, Codex and OpenCode. VS Code needs version 1.105 or later. Run the agent setup again after each Playwright upgrade, so the agents pick up the tools and instructions that release adds.
Yes, if nobody reviews what it changes. Its instructions let it edit expected values until a test passes. When it decides a failing test is right and the app is wrong, it marks the test to be skipped, and the build goes green. Review every heal like a code change.
No. Playwright drives web browsers, so on mobile it can only show how a web app behaves on a phone-sized screen, with a phone's screen size and touch input. Native iOS and Android apps need a mobile testing framework or platform instead.
Your team and Pie's QA team. Each test is plain steps you can read and edit, and every edit is saved as a version. Pie's QA team watches your coverage, and when a step breaks after an app change, Pie drafts the fix and the team reviews it before it lands.
Adithya Aggarwal
Adithya Aggarwal
CTO & Co-founder at Pie

Eight years building search and delivery systems at Amazon. The kind of scale where flaky tests block billion-dollar releases. Now CTO at Pie, building AI agents that adapt when your UI changes. LinkedIn →