Learn what Playwright Agents are, how the Planner, Generator, and Healer work, how to install them, and run a full step-by-step example.

Kailash Pathak
April 17, 2025
Maintaining a Playwright suite carries two predictable costs. Writing spec files for new features takes sprint time, and every frontend change breaks existing locators that you then have to fix. Playwright agents take on both tasks inside the framework you already use.
The framework ships three agents that divide the work. The planner opens the live application, explores it, and writes a test plan covering the main scenarios. The generator reads that plan and produces the actual spec files.
The healer runs with your tests and updates broken locators on its own, so a renamed button or a restructured component no longer fails the build.
Overview
What Are Agents in Playwright
Playwright Agents are three AI modules in Playwright v1.56 that automate test planning, code generation, and failure repair inside VS Code using a connected LLM.
How to Use Playwright Test Agents
Run npx playwright init-agents --loop=vscode in your project root to create the agents/ directory with all three agent definition files.
Each agent handles a distinct phase of the test lifecycle. Prompt them in sequence inside VS Code:
Playwright Agents are three AI modules built into Playwright v1.56 that automate test planning, code generation, and failure repair.
They run inside VS Code through Playwright's MCP and AI agents integration. Each agent reads its own definition file and uses the configured LLM to act on your prompt. Here is what each one does:
| Agent | Input | Output | Job |
|---|---|---|---|
| Planner | Running app + natural language prompt | test-plan.md | Explore flows, document test scenarios |
| Generator | test-plan.md + scenario reference | Playwright spec files (.spec.ts) | Write executable code with locators and assertions |
| Healer | Failing test output + error logs | Fixed spec files | Diagnose failures and apply targeted fixes |
Playwright ships three built-in agents: the Planner, the Generator, and the Healer. Each is scoped to one phase of the test lifecycle.
Note: Run your Playwright tests with AI across 50+ real browsers and OS combinations. Try TestMu AI Today!
Playwright Test Agents are built on top of the Model Context Protocol (MCP), which lets the agents use a connected LLM to reason about your app and generate or repair test code.
Each agent is defined by a Markdown file in agents/. When you prompt one in VS Code, Playwright passes its definition file, your prompt, and current context (DOM snapshot or failure output) to the LLM. The LLM decides what to do: open a browser, click, write a file, or fix a locator.
The agents operate in a defined handoff sequence:

The --loop=vscode flag chains all three agents and repeats until the suite is stable. You can also run agents individually: trigger only the Healer when a locator breaks, or only the Generator when you add new scenarios without re-running the Planner.
Each agent run is independent. The LLM stores no state between sessions, so prompt clarity and app stability directly determine output quality.
Playwright Agents extend an existing Playwright project. Initialize Playwright first, then add the agents.
Playwright Test Agents run inside VS Code and require an LLM provider connected through VS Code's agent panel. Without this, the agents initialize but do nothing when prompted.
If you do not have a Playwright project, follow the guide on how to install Playwright first, then return here for the agents setup. The command below installs browsers, generates playwright.config.ts, and scaffolds a tests/ directory.
npm init playwright@latestIf you already have a Playwright project with a config file, skip to Step 2.
Run this from your project root:
npx playwright init-agents --loop=vscodeThis creates an agents/ directory with three definition files:
agents/
├── playwright-test-planner.agent.md
├── playwright-test-generator.agent.md
└── playwright-test-healer.agent.mdDo not rename or delete these files. The --loop=vscode flag connects the agents to VS Code's agent panel so prompts route to the correct agent.
Open the project in VS Code. All three agents appear in the agent panel by name. They are ready immediately after initialization with no additional configuration.

Before running any agent, start your web application locally. The Planner and Generator open a real browser and interact with the running app. They cannot plan or generate tests against an app with inconsistent state, slow rendering, or auth-gated flows that have no active session.
Run the Planner to map your app's flows, pass the output to the Generator to create spec files, then use the Healer to fix any failures.
The example below runs all three agents in sequence on the TestMu AI eCommerce Playground. The flow covers login, adding a product to cart, and completing checkout. Each step shows the exact prompt, what the agent produces, and what to watch for before passing output to the next agent.
The Planner opens your app in a browser, navigates the specified flow, and writes a structured Markdown test plan. Give it a target URL and the flows you want documented.
Prompt:
Use the Playwright test planner to create a test plan and save it as test-plan.md.
On https://ecommerce-playground.lambdatest.io/: log in with test credentials, search for a laptop, add the first result to cart, proceed to checkout, and complete the order with test billing details.
The Planner writes test-plan.md to the project root with numbered scenarios, steps per scenario, and expected outcomes. Edit it before passing it to the Generator: remove out-of-scope flows, add edge cases the Planner missed. Here is what the output looks like:
# Test Plan
## 1. Checkout Flow
### 1.1 Successful Order with Valid Credentials
Steps:
1. Navigate to https://ecommerce-playground.lambdatest.io/
2. Log in with [email protected] / Test1234
3. Search for "laptop" and open the first result
4. Click Add to Cart, then Proceed to Checkout
5. Fill billing details and place the order
Expected: Order confirmation page displays with order IDUse fixed test data and a stable app state before running the Planner. Inconsistent state between runs produces gaps in the generated plan.

The Generator reads test-plan.md and converts one scenario into an executable Playwright spec file. Reference scenarios by number to prevent ambiguity.
Prompt:
Create a Playwright script for scenario 1.1 from test-plan.md using the Playwright test generator agent.
The Generator opens a browser, replays each step from the scenario in real time, and writes the spec file under tests/. It defaults to semantic locators like getByRole(), getByLabel(), and getByText(). See Playwright assertions for how these locators are used alongside expect() checks. Here is a representative output:
import { test, expect } from '@playwright/test';
test.describe('1.1 Successful Order with Valid Credentials', () => {
test('completes checkout and shows order confirmation', async ({ page }) => {
await page.goto('https://ecommerce-playground.lambdatest.io/');
await page.getByRole('link', { name: 'My Account' }).click();
await page.getByLabel('E-Mail Address').fill('[email protected]');
await page.getByLabel('Password').fill('Test1234');
await page.getByRole('button', { name: 'Login' }).click();
await page.getByRole('searchbox').fill('laptop');
await page.getByRole('button', { name: 'Search' }).click();
await page.locator('.product-thumb').first().click();
await page.getByRole('button', { name: 'Add to Cart' }).click();
await page.getByRole('link', { name: 'Checkout' }).click();
await expect(page.getByRole('heading', { name: 'Order Confirmed' })).toBeVisible();
});
});Run the generated spec locally before treating it as production-ready. Verify every assertion reflects the actual business requirement, not just that the page loaded.
Run the generated spec with the command below. The first run commonly fails because the Generator selected a locator that resolves to more than one element. For additional Playwright run tests options including filters and reporters, see the linked guide.
npx playwright test tests/checkout/checkout-valid.spec.tsA typical strict mode failure looks like this:
Error: strict mode violation: getByText('Login') resolved to 3 elementsPlaywright's strict mode requires every locator to match exactly one element. Do not fix this manually yet. Pass it to the Healer instead.

The Healer reads the failure output, identifies the root cause, and rewrites the affected spec. Point it at the failing file.
Prompt:
Identify the reason for the test failure in tests/checkout/checkout-valid.spec.ts and fix it using the Playwright Healer Agent.
The Healer inspects the DOM and rewrites the ambiguous locator. getByText('Login') matching three elements becomes getByRole('button', { name: 'Login' }). This is the same principle behind auto-heal in Playwright: narrow the selector to exactly one element.
The Healer reruns after each fix and continues until all tests pass or it hits its repair limit. Always review changes before committing. A fix can quietly alter what the test was originally verifying.

After the Healer applies fixes, re-run the suite to confirm the repair holds across all scenarios in the plan.
npx playwright testA clean run output looks like:
Running 3 tests using 1 worker
✓ tests/checkout/checkout-valid.spec.ts (4.2s)
✓ tests/checkout/checkout-guest.spec.ts (3.8s)
✓ tests/auth/login-valid.spec.ts (2.1s)
3 passed (11s)The spec is now stable for local CI. The next step is running it on a cloud grid against multiple browsers and OS combinations before merging.
Most Playwright Agent failures are not caused by the agents themselves. They come from environment mismatches, config path issues, or unstable app state.
This error appears when the agent cannot locate playwright.config.ts. It usually means the agent is running from a different working directory than expected.
Agents expect tests to live in standard locations. Non-standard paths cause the Generator to write files the Healer cannot find during repair.
Error: No tests found. Make sure the testDir in playwright.config.ts matches the location of your spec files.A mismatch between local and CI environments produces failures that look like test bugs but are dependency problems.
browserType.launch: Executable doesn't exist at /path/to/chromium
Run: npx playwright installWhen running agents in Playwright Docker or other CI environments, agents may lack the permissions needed to read config files or write test output.
Playwright Agents write tests inside your codebase. TestMu's KaneAI authors them from natural language, then exports directly to Playwright with no manual coding required.
Describe the flow in plain English and KaneAI maps it to a full Playwright spec with locators, assertions, and step structure already in place.
Features:
To get started, see the KaneAI getting started guide.
Playwright Agents produce better output when inputs are unambiguous and the environment is stable and predictable.
Playwright Agents take the mechanical work out of test authorship. The Planner maps your flows, the Generator writes the spec files, and the Healer keeps them passing when the UI changes.
Start with one flow. Run npx playwright init-agents --loop=vscode, prompt the Planner on your most-tested path, trim test-plan.md to the scenarios you need, and pass it to the Generator. Review every assertion before merging. Coverage decisions and business logic checks still belong to the engineer.
Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance