Generate and refine Playwright test scripts using the codegen recorder

domain: playwright.dev · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Run npx playwright codegen https://example.com to open a browser window and the Playwright Inspector side by side; all interactions in the browser are recorded as test code in real time
  2. Use CLI flags to pre-configure the recording session: --device='iPhone 14' for mobile emulation, --save-storage=auth.json to capture auth state at the end, or --load-storage=auth.json to start authenticated
  3. In the Inspector panel, switch the target language (JavaScript, TypeScript, Python, Java, C#) before copying the generated code
  4. After copying the generated script, replace any auto-generated CSS or XPath selectors with getByRole, getByLabel, or getByTestId locators for robustness, using the Inspector's locator picker to help identify ARIA-based alternatives
  5. Run the generated test with npx playwright test to verify it passes, then add assertions using expect() calls — codegen does not generate assertions automatically

Known gotchas

Related routes

Shard a Playwright test suite across multiple CI machines using --shard
playwright.dev · 5 steps · unrated
Capture and inspect a Playwright trace from a Robot Framework Browser library test suite
robotframework-browser.org · 5 steps · unrated
Record video mid-test on demand using Playwright page.screencast.start() and stop() (v1.59+)
playwright.dev · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans