Tutorial
Playwright test agents: planner, generator and healer
How Playwright's planner, generator and healer test agents work, how to set them up with Claude Code or VS Code, and how to review the tests they write for you.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
Playwright ships three test agents, introduced in version 1.56: a planner that explores your app and writes a test plan in Markdown, a generator that turns the plan into Playwright tests while checking locators against the live page, and a healer that runs failing tests, inspects the page and proposes fixes. They are not a separate product. They are agent definitions and an MCP server that your coding agent uses, so you drive them from Claude Code, VS Code, Codex or OpenCode.
Used well, they take the tedious parts of end-to-end testing off your hands: clicking through a flow to find the right locators, writing the boilerplate, chasing a renamed button. Used carelessly, they produce large suites of shallow tests that pass without proving much. This tutorial shows the workflow with Claude Code and where your judgement is needed.
1. Set up a project
If you already have a Playwright project, skip to the next step. Otherwise:
mkdir todo-tests && cd todo-tests
npm init playwright@latest
Accept the defaults (TypeScript, a tests folder). The examples below test Playwright’s public TodoMVC demo at https://demo.playwright.dev/todomvc, so you can follow along without your own app.
2. Generate the agent definitions
From the project root, run the command for your agent:
npx playwright init-agents --loop=claude
The other options are --loop=vscode, --loop=codex and --loop=opencode. For Claude Code the command creates:
.claude/agents/playwright-test-planner.md,playwright-test-generator.mdandplaywright-test-healer.md: subagent definitions, each with instructions and a list of allowed tools..mcp.json: registers Playwright’s test MCP server (npx playwright run-test-mcp-server), which gives the agents browser and test-runner tools.seed.spec.tsin your test directory: the starting point every planned test builds on.specs/: a folder for the Markdown test plans.
3. Write a seed test
The seed test sets up the environment: it navigates to the starting page and runs whatever fixtures, logins or data setup your tests need. The planner runs it before exploring, and the generator uses it as the template for new tests. Edit the generated tests/seed.spec.ts:
import { test, expect } from '@playwright/test';
test.describe('Test group', () => {
test('seed', async ({ page }) => {
await page.goto('https://demo.playwright.dev/todomvc');
});
});
For a real app, this is where you would use your authentication fixture and seed the database, so every generated test starts from a known state. Time spent on a good seed pays back in every generated test.
4. Plan
Start Claude Code in the project (claude). It will ask you to approve the new MCP server from .mcp.json; approve it. Then ask the planner for a plan, naming the agent and giving it a scope:
Use the playwright-test-planner agent to create a test plan for adding, completing
and filtering todos in the TodoMVC app. Use tests/seed.spec.ts as the seed.
Save it as specs/todo-basics.md.
The planner opens a browser, runs the seed, explores the interface and writes a Markdown plan: an overview of the feature, then numbered scenarios with steps and expected results, each pointing at the seed file. A scenario looks like this:
### 1. Adding New Todos
**Seed:** `tests/seed.spec.ts`
#### 1.1 Add Valid Todo
**Steps:**
1. Click in the "What needs to be done?" input field
2. Type "Buy groceries"
3. Press Enter key
**Expected Results:**
- The todo appears in the list
- The counter shows "1 item left"
5. Review the plan (this is the important step)
The plan is the cheapest place to catch problems, because it is short and written in plain language. Read it as a test lead would:
- Is anything important missing? The planner tests what it can see. It does not know your business rules, which edge cases have caused incidents or which flows matter most. Add them.
- Are the expected results real checks? “The page updates” is not an assertion. Every scenario should end with something observable and specific.
- Is anything pointless? Planners like to be thorough. Delete scenarios that test the framework rather than your app.
- Is the data realistic? Long names, Unicode, empty values and boundary numbers find more bugs than “Buy groceries”.
Edit the Markdown directly. It is your test plan now, and it belongs in version control alongside the tests.
6. Generate the tests
Ask the generator to implement the plan, or part of it:
Use the playwright-test-generator agent to generate tests for section 1 of
specs/todo-basics.md.
The generator works through each scenario in a live browser, performing the steps, choosing locators by checking them against the real page, and writing the assertions. Generated files reference the plan and seed in comments, and each step from the plan becomes a comment above its code:
// spec: specs/todo-basics.md
// seed: tests/seed.spec.ts
import { test, expect } from '@playwright/test';
test.describe('Adding New Todos', () => {
test('Add Valid Todo', async ({ page }) => {
await page.goto('https://demo.playwright.dev/todomvc');
// 1. Click in the "What needs to be done?" input field
const todoInput = page.getByRole('textbox', { name: 'What needs to be done?' });
await todoInput.click();
// 2. Type "Buy groceries"
await todoInput.fill('Buy groceries');
// 3. Press Enter key
await todoInput.press('Enter');
// Expect: the todo appears and the counter shows one item
await expect(page.getByTestId('todo-title')).toHaveText(['Buy groceries']);
await expect(page.getByTestId('todo-count')).toHaveText('1 item left');
});
});
The exact code depends on your app and the run. Run the suite yourself:
npx playwright test
npx playwright show-report
7. Review the generated tests
Read every generated test before merging it, with three questions:
- Would this test fail if the feature broke? Temporarily break the behaviour (or edit the expected text) and check. A test that still passes is decoration.
- Are the locators robust? Prefer roles, labels and test ids over CSS classes and positions. The generator usually does this, but check.
- Is it independent? Tests should not rely on the order they run in or on data left by other tests. That is what the seed and fixtures are for.
8. Heal failures, carefully
When the UI changes and tests fail, ask the healer to investigate:
Use the playwright-test-healer agent to fix the failing test "Add Valid Todo".
The healer runs the test, inspects the page where it fails, proposes a patch (often a new locator or a changed wait) and re-runs it until it passes. If it concludes the functionality itself is broken rather than the test, it can mark the test as skipped instead.
That last behaviour is the reason to review healed tests closely. A healer that makes a test pass by changing its assertion has hidden a bug. Treat every healer change as a pull request: read the diff, and ask whether the test changed because the app legitimately changed or because the test was weakened. A skipped test is a bug report until proven otherwise.
Pitfalls
Generating a huge suite on day one. Start with one critical journey, review it thoroughly, and grow from there. A small suite you trust beats a large one you do not.
Letting the healer auto-merge. Healed changes need the same review as any other code change, ideally with a note on why the test broke.
Skipping the seed. Without a proper seed, the agents improvise setup, and tests become slow and inconsistent.
Testing what the planner happened to see. It cannot know about the bug from last quarter. Your domain knowledge goes into the plan.
Stale agent definitions. Regenerate them after Playwright upgrades.
Next steps
- Run the full process on your own app with the generate Playwright tests with agents workflow.
- Read AI for QA engineers for where these tools help and where they do not.
- Follow the AI for test engineers learning path.
- Repair broken tests with review in fix flaky tests with a healer agent.
- Explore an app before you write a plan with Playwright MCP for exploratory testing.
- Draft the test ideas themselves with AI test case design.
Covers
Check your understanding
Playwright test agents quiz
Playwright's planner, generator and healer agents: setup, what each produces, and reviewing their output.
7 questions · pass mark 70%
Review
Related
- Generate Playwright tests with AI agents, then review them
Approve a test plan before any code exists, generate tests from it and review them like production code.
- Getting started with AI test case design
Use a language model to draft test cases for a feature, prompt it for coverage rather than happy paths, and review its ideas like a tester before you automate.
- AI for QA engineers: where it helps and where it doesn't
Where it helps in test design, agent-written tests and self-healing, where it does not, and the testing skills worth building.
- AI for test engineers
An AI course for testers: apply generative AI to everyday test automation, from AI-assisted test design to generating, healing and reviewing Playwright tests.
- Web app testing
Tests local web apps by writing Python Playwright scripts, with a helper that starts your dev servers first, plus screenshots and console log capture.