Playwright
Testing Agents
Tutorial
Learn how Playwright's Planner, Generator and Healer agents can explore an application, design test coverage, generate executable tests and help repair failures.
Test automation is becoming agentic
Traditional automation starts with a human deciding what to test, writing the test and maintaining it. Playwright Testing Agents add another layer: specialised AI agents can participate in each of those activities.
Playwright currently provides three specialised testing agents: Planner, Generator and Healer.
You can use them independently, sequentially, or as part of a larger agentic testing workflow.
Three agents. Three different jobs.
A useful way to understand the model is to imagine a miniature automation team.
Planner
Explores the application and turns a testing objective into a structured Markdown test plan containing scenarios and user flows.
Generator
Reads the plan and translates scenarios into executable Playwright Test files, locators, actions and assertions.
Healer
Runs tests, investigates failures and attempts to repair tests when the application or automation needs adjustment.
From business intent to executable tests
Planner
Explores the product and identifies scenarios, actions and expected outcomes.
Generator
Converts the approved plan into runnable Playwright tests.
Healer
Executes tests, investigates failures and proposes or applies repairs.
What you'll need
You need a Playwright project plus a compatible coding-agent environment.
- Node.js installed
- A Playwright Test project
- Your preferred supported agent loop
- A web application or demo application to test
- Basic understanding of Playwright tests is useful, but not essential
Step 1 — Create or open a Playwright project
If you do not already have a Playwright project, initialise one.
npm init playwright@latest
Follow the prompts to create your project and install the required browser dependencies.
Step 2 — Initialise Playwright agents
Playwright provides an init-agents command that generates the agent definitions required by your chosen environment.
For VS Code
npx playwright init-agents --loop=vscode
For Claude Code
npx playwright init-agents --loop=claude
For Codex
npx playwright init-agents --loop=codex
Our practice scenario
Imagine we are testing a simple task-management application. The feature allows users to create, complete, filter and remove tasks.
Business requirement
A user should be able to create tasks, mark tasks as complete, view active or completed tasks and clear completed tasks.
Our QA objective
Build meaningful automated coverage of the core user journey without manually writing every scenario from scratch.
Step 3 — Give Planner a seed test
A seed test can initialise the environment and place the agent in the right application context before exploration begins.
import { test, expect } from '@playwright/test';
test('open task application', async ({ page }) => {
await page.goto('YOUR_APPLICATION_URL');
await expect(page).toHaveTitle(/Todo|Tasks/i);
});
The seed does not need to contain the entire test suite. Think of it as the starting position from which the Planner can explore.
Planner — explore before you automate
Planner explores the application and creates a Markdown test plan. This is potentially the most important stage because poor coverage automated perfectly is still poor testing.
A better prompt
Create a test plan for the core task-management workflow. Cover creation, validation, completion, filtering, deletion, useful boundary cases and important user-state transitions. Prioritise scenarios by business risk.
Notice that we did not simply say: "test this page."
A good tester gives the agent context about risk, scope and expected coverage.
Verify a valid task appears in the active task list.
Verify blank or unsupported input is handled appropriately.
Verify status and remaining task count are updated.
Verify only completed tasks remain visible.
Verify completed tasks are removed while active tasks remain.
Generator — turn the plan into code
Once you are comfortable with the coverage, Generator can convert the test plan into executable Playwright Test files.
Generate Playwright tests from the approved task-management test plan. Use resilient user-facing locators, web-first assertions and keep each test focused on a clear behaviour.
A generated test could conceptually look like this:
import { test, expect } from '@playwright/test';
test.beforeEach(async ({ page }) => {
await page.goto('YOUR_APPLICATION_URL');
});
test('user can create a task', async ({ page }) => {
const taskInput = page.getByPlaceholder(
'What needs to be done?'
);
await taskInput.fill('Review regression results');
await taskInput.press('Enter');
await expect(
page.getByText('Review regression results')
).toBeVisible();
});
test('user can complete a task', async ({ page }) => {
const taskInput = page.getByPlaceholder(
'What needs to be done?'
);
await taskInput.fill('Run smoke tests');
await taskInput.press('Enter');
await page
.getByRole('checkbox', { name: /toggle todo/i })
.check();
await expect(
page.getByText('Run smoke tests')
).toBeVisible();
});
Do not stop at “the code runs”
Review generated automation exactly as you would review human-written automation.
- Are assertions meaningful?
- Are locators resilient?
- Are tests independent?
- Is setup unnecessarily duplicated?
- Could the test pass even when the feature is broken?
- Are important business validations missing?
Now run the tests
Generated automation becomes useful only when it survives execution against the real application.
npx playwright test
This is where flaky selectors, unexpected states, incorrect assumptions and genuine product defects reveal themselves.
Healer — investigate failures intelligently
Healer executes the suite, examines failures and can attempt to repair failing tests.
Before
Automation expects a button labelled "Submit Order".
page.getByRole(
'button',
{ name: 'Submit Order' }
)
The UI has changed and now uses "Place Order".
After
Healer explores the current application state and identifies a potential test repair.
page.getByRole(
'button',
{ name: 'Place Order' }
)
The repaired test can then be rerun and validated.
Should the test be healed — or should the product be fixed?
| Situation | Likely interpretation | Tester action |
|---|---|---|
| Button deliberately renamed | Expected UI change | Update automation after verifying requirement |
| Expected checkout button disappeared | Possible regression | Investigate product before healing test |
| Selector tied to fragile CSS changed | Automation maintenance issue | Replace with resilient locator |
| Business total is incorrect | Product defect | Do not “heal” the assertion to match bad behaviour |
| Application is temporarily unavailable | Environment/infrastructure issue | Investigate environment |
What an agent-assisted testing workflow looks like
Agent responsibility vs tester responsibility
Let agents accelerate
- Application exploration
- Drafting test scenarios
- Generating repetitive test code
- Locating UI elements
- Running automation
- Investigating routine failures
- Suggesting test repairs
Tester must still own
- Business risk
- Test strategy
- Coverage decisions
- Requirement interpretation
- Oracle quality
- Defect vs test-failure judgement
- Release confidence
What changes for QA professionals?
Less mechanical coding
Agents can reduce time spent translating obvious scenarios into repetitive automation code.
More emphasis on intent
The value of the tester moves upward toward risk, questioning, coverage and evaluation.
New failure modes
AI-generated tests can contain weak assertions, incorrect assumptions and misleading confidence.
Common mistakes with AI-generated tests
Automating incorrect assumptions
The agent may misunderstand the intended business behaviour. A syntactically correct test can still be logically wrong.
Weak assertions
A test may perform many actions but verify very little. Activity is not the same as validation.
Happy-path bias
Exploration can naturally gravitate toward visible, straightforward paths while missing deeper risks.
Healing a real defect
Never change expected behaviour merely because an agent discovers the current application behaves differently.
Unstable test data
Generated tests can inherit shared state or fragile data, making the resulting suite flaky.
False confidence
A large number of generated automated tests does not automatically equal meaningful product coverage.
The 7-step responsible agentic testing workflow
Define the testing mission
Tell the agent what quality risk or business objective you are trying to investigate.
Provide context
Give it useful requirements, domain rules, fixtures and starting state instead of expecting it to guess.
Let Planner explore
Use exploration to draft coverage, not as an automatic replacement for your test strategy.
Review the plan
Add missing risks, negative scenarios, boundaries and business-critical behaviour.
Generate and review automation
Check locators, assertions, data, isolation and code maintainability.
Execute and investigate
Distinguish product defects, test problems, environment issues and expected application changes.
Heal with human oversight
Accept repairs only when they preserve the intended behaviour and testing objective.
Playwright Testing Agents cheat sheet
npm init playwright@latest
npx playwright init-agents --loop=vscode
npx playwright init-agents --loop=claude
npx playwright init-agents --loop=codex
npx playwright test
Application → exploration → Markdown test plan
Approved plan → Playwright Test files
Execution → failure investigation → test repair
Interview questions to remember
What does the Playwright Planner agent do?
It explores an application based on the testing objective and produces a structured Markdown test plan.
What is the role of Generator?
Generator converts the test plan into executable Playwright Test files.
What does Healer do?
It runs the test suite, investigates failures and can attempt to repair failing tests.
What is the biggest risk of self-healing tests?
Mistaking genuine product regression for test maintenance and changing automation so that defective behaviour appears valid.
Do AI testing agents replace testers?
They automate and accelerate parts of exploration, generation and maintenance. Human judgement remains essential for risk, strategy, expected behaviour, coverage and release decisions.
Frequently asked questions
Are Playwright Testing Agents the same as Playwright MCP?
Can Planner automatically decide my complete test strategy?
Should every failing test be given to Healer?
Are generated tests production-ready?
Do I still need to learn Playwright?
Is agentic testing only useful for UI tests?
Playwright agents are only the beginning.
Planner, Generator and Healer show how software testing is shifting from simple script automation toward collaborative workflows in which testers define risk and intent while agents help explore, generate, execute and maintain automation.
The next tutorial in this series will go one level deeper: Playwright MCP — letting an AI agent interact directly with the browser.