Playwright Generate Tests
Generate production-ready Playwright tests from a user story, URL, component path, or feature description.
Steps
Understand the target — user story → behavior to verify; component path → read source for props/states/interactions; page/URL → route + elements; feature → app areas.
Explore the codebase — read playwright.config.ts (testDir/baseURL/projects), existing tests for patterns/fixtures/conventions, the component source, existing page objects (pages/), fixtures (fixtures/), auth setup (auth.setup.ts/storageState).
Select a template matching the surface (auth, CRUD, checkout, search, forms, dashboard, settings, onboarding, API, accessibility); replace placeholders with real selectors/URLs/data.
Generate the test — Arrange/Act/Assert in test.describe blocks.
- Locator priority: getByRole → getByLabel → getByText → getByPlaceholder → getByTestId.
- Web-first assertions only:
await expect(locator).toBeVisible() / .toHaveText() — never const t = await page.textContent(); expect(t).toBe().
- Never use
waitForTimeout(), page.$()/$$(), bare CSS unless necessary, or page.evaluate() for locator-doable work.
- Always: descriptive names explaining behavior, error/edge tests alongside happy path,
await on every Playwright call, baseURL-relative navigation (page.goto('/')).
Match conventions — TS → .spec.ts, JS → .spec.js with require(); reuse project page objects, custom fixtures, and test-data dir.
Supporting files when warranted — page object if a test touches 5+ unique locators on one page; fixture for shared setup (auth/data); JSON in test-data/ for structured data.
Verify — run npx playwright test <file> --reporter=list; on failure fix the test (not the app), re-run; if it's a genuine app issue, report it.
Output
Generated file(s) + path, any supporting files, run result, coverage note (what behaviors are now tested).
1---2name: playwright-generate-tests3description: Use when writing or generating Playwright tests from a user story, URL, component, or feature ("write tests", "add tests for", "test this component", "e2e test for").4tags: [playwright, test-generation, e2e, locators, web-first-assertions, page-objects, fixtures, templates]5source: alirezarezvani/claude-skills6derived_from: engineering-team/playwright-pro/skills/generate7metadata:8 source: https://skillmd.com/skills/aashutosh396/playwright-generate-tests9---1011# Playwright Generate Tests1213Generate production-ready Playwright tests from a user story, URL, component path, or feature description.1415## Steps16171. **Understand the target** — user story → behavior to verify; component path → read source for props/states/interactions; page/URL → route + elements; feature → app areas.18192. **Explore the codebase** — read `playwright.config.ts` (testDir/baseURL/projects), existing tests for patterns/fixtures/conventions, the component source, existing page objects (`pages/`), fixtures (`fixtures/`), auth setup (`auth.setup.ts`/`storageState`).20213. **Select a template** matching the surface (auth, CRUD, checkout, search, forms, dashboard, settings, onboarding, API, accessibility); replace placeholders with real selectors/URLs/data.22234. **Generate the test** — Arrange/Act/Assert in `test.describe` blocks.24 - Locator priority: getByRole → getByLabel → getByText → getByPlaceholder → getByTestId.25 - Web-first assertions only: `await expect(locator).toBeVisible()` / `.toHaveText()` — never `const t = await page.textContent(); expect(t).toBe()`.26 - Never use `waitForTimeout()`, `page.$()/$$()`, bare CSS unless necessary, or `page.evaluate()` for locator-doable work.27 - Always: descriptive names explaining behavior, error/edge tests alongside happy path, `await` on every Playwright call, baseURL-relative navigation (`page.goto('/')`).28295. **Match conventions** — TS → `.spec.ts`, JS → `.spec.js` with `require()`; reuse project page objects, custom fixtures, and test-data dir.30316. **Supporting files when warranted** — page object if a test touches 5+ unique locators on one page; fixture for shared setup (auth/data); JSON in `test-data/` for structured data.32337. **Verify** — run `npx playwright test <file> --reporter=list`; on failure fix the test (not the app), re-run; if it's a genuine app issue, report it.3435## Output36Generated file(s) + path, any supporting files, run result, coverage note (what behaviors are now tested).