Skip to content

Commit 7d89dd7

Browse files
committed
docs: replace Playwright MCP workflow with Playwright Test Agents
Switch E2E testing to use Playwright Test Agents (planner, generator, healer) instead of manual Playwright MCP workflow. Remove data-testid requirements from coding standards — use semantic selectors instead.
1 parent 83a6647 commit 7d89dd7

2 files changed

Lines changed: 37 additions & 54 deletions

File tree

docs/coding-standards.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,6 @@ try {
2727
}
2828
```
2929

30-
## Test Attributes
31-
32-
All interactive elements must have `data-testid` for E2E testing. Non-interactive display elements do not need it.
33-
34-
**What needs `data-testid`**: buttons, inputs, links, form controls, list containers, dialog triggers, dropdowns.
35-
36-
**Naming convention**: `<context>-<element>`, lowercase with `-`:
37-
38-
```tsx
39-
<Button data-testid="create-user-btn">Create</Button>
40-
<Input data-testid="user-name-input" />
41-
<ul data-testid="user-list">
42-
<li data-testid={`user-item-${user.id}`}>...</li>
43-
</ul>
44-
<Dialog>
45-
<DialogTrigger data-testid="edit-user-dialog-trigger" />
46-
<DialogContent data-testid="edit-user-dialog">...</DialogContent>
47-
</Dialog>
48-
```
49-
5030
## Code Quality
5131

5232
- Linting and formatting: Biome.

docs/testing.md

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,30 @@ pnpm --filter <package> test # Run tests for a specific package
2121
pnpm --filter <package> test --watch # Watch mode
2222
```
2323

24-
## E2E Tests — AI-Assisted Playwright Workflow
24+
## E2E Tests — Playwright Test Agents
2525

26-
E2E tests follow a two-phase AI-assisted workflow using [Playwright MCP](https://github.com/microsoft/playwright-mcp).
26+
E2E tests use [Playwright Test Agents](https://playwright.dev/docs/test-agents) for AI-assisted test creation, generation, and self-healing.
2727

28-
### Prerequisites
28+
### Setup
2929

30-
- All interactive elements must have `data-testid` attributes (see `docs/coding-standards.md`)
31-
- Playwright tests use `page.getByTestId()` for element selection — stable across UI refactors
30+
Initialize Playwright Test Agents in the project:
3231

33-
### Phase 1: Write Test Specs as Natural Language
32+
```bash
33+
npx playwright init-agents --loop=claude
34+
```
35+
36+
This sets up agent definitions under `.github/` with all necessary MCP tools and instructions — no separate skills installation required. Regenerate after Playwright updates to access new tools.
37+
38+
### Workflow
39+
40+
#### Step 1: Planner Agent — Create Test Specs
41+
42+
Based on user descriptions or PRD documents, use the **Planner Agent** to explore the running app and produce markdown test plans:
3443

35-
Create `.md` files describing user scenarios from the user's perspective:
44+
- Input: user scenario description or PRD document
45+
- Output: structured markdown spec file under `e2e/specs/`
46+
47+
The planner navigates the app, discovers page structure, and writes human-readable test plans with steps and expected results.
3648

3749
```markdown
3850
<!-- e2e/specs/user-crud.md -->
@@ -49,50 +61,41 @@ Create `.md` files describing user scenarios from the user's perspective:
4961
9. Verify the user is removed from the list
5062
```
5163

52-
### Phase 2: Generate Playwright Tests via Playwright MCP
64+
#### Step 2: Generator Agent — Create Test Files
5365

54-
1. AI reads the `.md` spec file
55-
2. AI uses **Playwright MCP** to navigate the running app, following the spec steps:
56-
- Navigate to pages, click elements, fill forms, observe results
57-
- Discover `data-testid` attributes and page structure via Playwright's built-in selectors (`getByTestId`, `getByRole`, etc.)
58-
3. AI generates a Playwright test file using the observed selectors:
66+
Use the **Generator Agent** to transform markdown specs into executable Playwright test files:
5967

60-
```
61-
e2e/specs/user-crud.md ← Human-written scenario
62-
e2e/tests/user-crud.spec.ts ← AI-generated Playwright test
63-
```
68+
- Input: markdown spec from `e2e/specs/`
69+
- Output: Playwright test file under `e2e/tests/`
70+
- The generator verifies selectors and assertions live against the running app using semantic selectors (`getByRole`, `getByText`, `getByLabel`, `getByPlaceholder`)
6471

65-
Example generated output:
66-
67-
```ts
68-
test('user CRUD operations', async ({ page }) => {
69-
await page.goto('/playground/components/users');
70-
await page.getByTestId('user-name-input').fill('Test User');
71-
await page.getByTestId('user-email-input').fill('test@example.com');
72-
await page.getByTestId('create-user-btn').click();
73-
await expect(page.getByText('Test User')).toBeVisible();
74-
// ...
75-
});
76-
```
72+
#### Step 3: Healer Agent — Run & Fix Tests
73+
74+
Use the **Healer Agent** to execute tests and automatically repair failures:
75+
76+
- Replays failing steps and inspects the current UI
77+
- Suggests patches (locator updates, wait adjustments, data fixes)
78+
- Re-runs until passing or guardrails activate
7779

7880
### File Structure
7981

8082
```
8183
e2e/
82-
├── specs/ ← Human-written natural language scenarios
84+
├── specs/ ← Markdown test plans (planner output)
8385
│ ├── user-crud.md
8486
│ ├── file-upload.md
8587
│ └── ssr-demo.md
86-
└── tests/ ← AI-generated Playwright tests
88+
└── tests/ ← Playwright test files (generator output)
89+
├── seed.spec.ts ← Bootstrap environment
8790
├── user-crud.spec.ts
8891
├── file-upload.spec.ts
8992
└── ssr-demo.spec.ts
9093
```
9194

9295
### Key Principles
9396

94-
- **Specs are the source of truth**humans write and maintain the `.md` files
95-
- **`data-testid` is the contract**UI can refactor freely as long as testids stay stable
97+
- **Specs are the source of truth**review and maintain the markdown plans
98+
- **Use semantic selectors**prefer `getByRole`, `getByText`, `getByLabel` over fragile CSS selectors or testids
9699
- **Generated tests run without AI** — standard Playwright in CI, no API keys needed
97-
- **Regenerate, don't hand-edit** — when UI changes, re-run Playwright MCP observation to update tests
100+
- **Use healer to fix flaky tests**don't hand-edit generated tests, let the healer agent repair them
98101
- Keep specs focused: one user flow per file

0 commit comments

Comments
 (0)