The difference between an agent that writes your team's Playwright and an agent that writes generic Playwright is what you feed it before the first prompt: a rules file carrying your conventions, and a written spec of what to test. Spec-first authoring makes the agent a fast junior who read the handbook.
Tier: Core · Workflow area: Automation engineering
This playbook establishes the professional workflow for generating end-to-end tests with Claude Code, Cursor, or Copilot: conventions loaded as persistent rules, a reviewed spec before any code, generation in small increments, and an assertion-strength review before merge. It is the manual-authoring counterpart to the fully agentic planner/generator loop in pb-15.
When NOT to use:
npx playwright test in the loop.Write the rules file once. In the repo root, CLAUDE.md (Claude Code) or .cursor/rules/playwright.mdc (Cursor):
## Playwright conventions
- Locators: getByRole/getByLabel/getByTestId only. Never CSS or XPath.
- No page.waitForTimeout. Rely on web-first assertions and auto-waiting.
- Use fixtures from tests/fixtures.ts for auth and seeded data — never
inline login steps in a spec.
- One user-visible behavior per test; name as "does X when Y".
- Assert outcomes users can see (URL, text, ARIA state), not network
internals, unless the spec says otherwise.
- New helpers go in tests/support/, exported and typed.
Write the spec before the prompt. Five minutes in a scratch file — behaviors, data, and edge cases you decided on (pb-01 and pb-05 feed this):
Feature: coupon redemption at checkout
1. Valid coupon reduces total and shows applied badge.
2. Expired coupon → inline error "This code has expired", total unchanged.
3. Coupon + already-discounted item → no stacking; explains why.
4. Removing coupon restores original total.
Data: use seedCart fixture; coupons in tests/data/coupons.json.
Prompt for one spec file, referencing both artifacts:
Read tests/fixtures.ts and tests/checkout/cart.spec.ts for style.
Implement tests for the spec in scratch/coupon-spec.md as
tests/checkout/coupon.spec.ts. Follow the conventions file strictly.
After writing, run only this file and iterate until green:
npx playwright test tests/checkout/coupon.spec.ts
Do not modify fixtures or other specs without asking.
The agent runs the suite, reads failures, and fixes its own selector typos — that loop is the productivity core. Your job resumes when it reports green.
Review for assertion strength, not style. Style is the rules file's job; your review targets what the agent gets wrong invisibly:
npx playwright test tests/checkout/coupon.spec.ts --repeat-each=3
grep -n "waitForTimeout\|toBeVisible()" tests/checkout/coupon.spec.ts
Read every expect: does the expired-coupon test assert the total stayed unchanged, or only that the error appeared? Agents systematically write the assertion that detects success and omit the one that detects damage. A strong generated test looks like:
test('does not stack coupon on discounted items', async ({ seededCart }) => {
await seededCart.addItem('sale-hoodie');
await seededCart.applyCoupon('SAVE20');
await expect(seededCart.page.getByRole('alert'))
.toHaveText(/can't be combined with sale items/);
await expect(seededCart.total()).toHaveText('€39.99'); // unchanged
});
Gate the merge like any code. PR review applies the pb-13 rubric; CI runs the file with retries off so latent flake surfaces now, on the branch, not next Tuesday on main.
An agent that cannot run the tests is autocomplete with confidence — always grant it the test command, because code that has never executed is the primary source of AI-authored suite rot.
.github/copilot-instructions.md; use agent mode for the write-run-fix loop, and paste the spec into the chat since Copilot won't reliably read scratch files unprompted.cy.wait(ms) and mandates data-cy selectors; the agent runs npx cypress run --spec in the loop.--repeat-each=3 before merge; agent-authored waits are the top flake source (pb-19's taxonomy).The rules file and the spec are the actual work; the generation is nearly free. Teams that invest in conventions-as-context get compounding suite consistency — teams that just prompt get a fast-growing suite in five styles that nobody owns.