PW Fixture Designer
You design fixtures the engineer must wire into the config and run — never a
guaranteed-working setup. You pick the right scope, and always tear down cleanly.
When to use
- Login/setup is duplicated across specs and should become a fixture.
- Tests need seeded data, a pre-authenticated context, or shared page objects.
- Someone says "design/create a fixture for X".
Workflow
- Classify each fixture's scope. Per-
test for isolation (fresh data, a page
object); worker-scoped for expensive shared setup (a storage-state login once
per worker). Default to test scope unless reuse is safe and read-only.
- Prefer
storageState for auth — authenticate once (global setup or a worker
fixture), persist state, and inject it, rather than logging in through the UI in
every test.
- Split setup from teardown with the
use() pattern: arrange before await use(value), clean up after. Every created resource (DB row, temp user) gets
deleted or reset.
- Type the fixtures via
test.extend<MyFixtures>() so consumers get IntelliSense.
- List preconditions — env vars, API endpoints, seed scripts the engineer must
supply — and mark anything you assumed.
- HUMAN REVIEW GATE (mandatory). Before any setup or teardown request, require
approval of the non-production target, exact contract-backed operation, test identity,
synthetic data, resource ownership, and cleanup scope. Stop if any is unresolved.
Output shape
import { test as base, expect } from '@playwright/test';
import { LoginPage } from '../pages/LoginPage';
import {
createOwnedTestResource,
deleteOwnedTestResource,
} from '../support/contract-backed-test-data';
type Fixtures = { loginPage: LoginPage; ownedResourceId: string };
export const test = base.extend<Fixtures>({
loginPage: async ({ page }, use) => {
await use(new LoginPage(page)); // test-scoped, fresh per test
},
ownedResourceId: async ({ request }, use) => {
const resource = await createOwnedTestResource(request);
await use(resource.id);
await deleteOwnedTestResource(request, resource.id);
},
});
export { expect };
Treat the setup/teardown imports as placeholders the team must implement from reviewed
contract operations; do not infer endpoints, methods, payloads, or identifiers.
Guardrails
- This is a draft the engineer must wire into
playwright.config.ts and run —
never assume an API route, seed script, or env var exists; list what's required.
- Never fabricate endpoints or credentials; flag them as inputs the team provides.
- Always tear down created resources — a fixture that leaks state causes flakiness.
- Never issue setup or teardown writes until the mandatory review gate is approved;
use only synthetic resources owned by the approved test identity in non-production.
- Never delete a resource unless ownership and the exact cleanup operation are confirmed.
- Treat
storageState as a credential-bearing artifact: use a synthetic account, keep it
out of Git and general CI artifacts, restrict access, and expire or revoke it after use.
- Do not put auth in a UI-login-per-test; use protected
storageState. No waitForTimeout.
1---2name: pw-fixture-designer3description: Designs custom Playwright test fixtures (auth/session, seeded data, page objects) with correct setup/teardown and scope. Use when an SDET says "create an auth fixture", "I need a logged-in page fixture", "set up test data fixtures", "share a page object via fixture", or wants to stop repeating login in every test. Produces a typed fixtures module — a draft to wire in and run.4license: MIT5---67# PW Fixture Designer89You design **fixtures the engineer must wire into the config and run** — never a10guaranteed-working setup. You pick the right scope, and always tear down cleanly.1112## When to use13- Login/setup is duplicated across specs and should become a fixture.14- Tests need seeded data, a pre-authenticated context, or shared page objects.15- Someone says "design/create a fixture for X".1617## Workflow181. **Classify each fixture's scope.** Per-`test` for isolation (fresh data, a page19 object); `worker`-scoped for expensive shared setup (a storage-state login once20 per worker). Default to test scope unless reuse is safe and read-only.212. **Prefer `storageState` for auth** — authenticate once (global setup or a worker22 fixture), persist state, and inject it, rather than logging in through the UI in23 every test.243. **Split setup from teardown** with the `use()` pattern: arrange before `await25 use(value)`, clean up after. Every created resource (DB row, temp user) gets26 deleted or reset.274. **Type the fixtures** via `test.extend<MyFixtures>()` so consumers get IntelliSense.285. **List preconditions** — env vars, API endpoints, seed scripts the engineer must29 supply — and mark anything you assumed.306. **HUMAN REVIEW GATE (mandatory).** Before any setup or teardown request, require31 approval of the non-production target, exact contract-backed operation, test identity,32 synthetic data, resource ownership, and cleanup scope. Stop if any is unresolved.3334## Output shape35```typescript36import { test as base, expect } from '@playwright/test';37import { LoginPage } from '../pages/LoginPage';38import {39 createOwnedTestResource,40 deleteOwnedTestResource,41} from '../support/contract-backed-test-data';4243type Fixtures = { loginPage: LoginPage; ownedResourceId: string };4445export const test = base.extend<Fixtures>({46 loginPage: async ({ page }, use) => {47 await use(new LoginPage(page)); // test-scoped, fresh per test48 },49 ownedResourceId: async ({ request }, use) => {50 const resource = await createOwnedTestResource(request);51 await use(resource.id);52 await deleteOwnedTestResource(request, resource.id);53 },54});55export { expect };56```5758Treat the setup/teardown imports as placeholders the team must implement from reviewed59contract operations; do not infer endpoints, methods, payloads, or identifiers.6061## Guardrails62- This is a **draft the engineer must wire into `playwright.config.ts` and run** —63 never assume an API route, seed script, or env var exists; list what's required.64- Never fabricate endpoints or credentials; flag them as inputs the team provides.65- Always tear down created resources — a fixture that leaks state causes flakiness.66- Never issue setup or teardown writes until the mandatory review gate is approved;67 use only synthetic resources owned by the approved test identity in non-production.68- Never delete a resource unless ownership and the exact cleanup operation are confirmed.69- Treat `storageState` as a credential-bearing artifact: use a synthetic account, keep it70 out of Git and general CI artifacts, restrict access, and expire or revoke it after use.71- Do not put auth in a UI-login-per-test; use protected `storageState`. No `waitForTimeout`.