Skip to main content

Playwright Test Generator

Generate *.spec.ts Playwright tests instantly. Select your browser target, test type, and locators — get complete TypeScript output using page.goto, the Locator API, page.route() mocking, and expect assertions. Ready to copy and run.

✓ Chromium, Firefox, WebKit & All 3 ✓ Locator API (getByTestId, getByRole) ✓ page.route() network mocking ✓ TypeScript output

Frequently Asked Questions

What is Playwright and how does it differ from Cypress?▼

Playwright is an E2E testing framework from Microsoft that supports Chromium, Firefox, and WebKit in a single test run. Unlike Cypress (which runs inside the browser), Playwright drives browsers externally via DevTools Protocol, enabling true multi-tab testing, native file uploads, and parallel browser testing. Playwright's async/await API is more idiomatic for TypeScript developers, and its Locator API has built-in auto-waiting so you rarely need explicit waits.

What is the Locator API and why is it preferred?▼

Playwright's Locator API (page.locator(), page.getByTestId(), page.getByRole(), page.getByText()) is the recommended way to find elements. Unlike page.$() (which returns a static ElementHandle that can go stale), Locators are lazy — they re-query the DOM on every action and automatically wait for the element to be actionable. This eliminates most timing-related flakiness. Use page.getByTestId() for data-testid attributes and page.getByRole() for accessible elements.

How does page.route() work for network mocking?▼

page.route(pattern, handler) intercepts network requests matching the glob pattern (e.g. '**/api/users'). In the handler, you can call route.fulfill({ status, body }) to return a fake response, route.abort() to simulate network errors, or route.continue() to pass through. This lets you test loading states, error handling, and edge cases without a real backend. Always set up routes before navigating to the page.

How do I run Playwright tests across all browsers?▼

Configure projects in playwright.config.ts: each project specifies a browser via devices (e.g. devices['Desktop Chrome']). Run npx playwright test to execute all projects, or npx playwright test --project=chromium for one browser. In CI, run them in parallel with workers: 4. The Playwright HTML reporter (npx playwright show-report) shows results per browser with screenshots and traces.

What is Playwright Tracing and when should I use it?▼

Playwright traces (trace: 'on-first-retry' or 'retain-on-failure' in playwright.config.ts) record a complete timeline of your test — screenshots, network requests, console logs, and DOM snapshots at every step. When a test fails in CI, download the trace.zip and open it with npx playwright show-trace trace.zip. You get a full interactive timeline to debug exactly where the test diverged from expectations.

How do I test mobile viewports with Playwright?▼

Use devices from @playwright/test: import { devices } from '@playwright/test'. Then in your playwright.config.ts projects, add { name: 'Mobile Chrome', use: { ...devices['Pixel 5'] } }. Within a test, override with await page.setViewportSize({ width: 375, height: 667 }). You can also emulate geolocation, timezone, and device pixel ratio. Run mobile tests in parallel with desktop tests using separate project configs.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →