Cursorcursorintermediate
Add Playwright E2E Tests to Next.js (Cursor Prompt)
Cursor prompt to add Playwright end-to-end tests for authentication, CRUD operations, and payment flows.
What you'll get
Playwright E2E test suite covering auth flows, CRUD operations, and payment flows with Page Object Model.
The Prompt
Add Playwright end-to-end tests to this Next.js application. FILES TO CREATE: - playwright.config.ts — Playwright configuration - tests/auth.spec.ts — Authentication flow tests - tests/crud.spec.ts — CRUD operation tests - tests/payments.spec.ts — Payment flow tests - tests/fixtures.ts — Shared test fixtures and helpers - tests/helpers/auth.ts — Auth helper functions CONFIGURATION: - Use Chromium only for CI speed. Use all browsers locally. - Base URL: http://localhost:3000 - Add webServer config to auto-start Next.js dev server. - Enable trace on first retry for debugging. - Screenshots on failure. TEST SUITES: 1. Auth tests: signup, signin, password reset, protected route redirect, signout 2. CRUD tests: create item, read list, update item, delete item, form validation errors 3. Payment tests: view pricing, start checkout (mock Stripe in test mode), handle success redirect PATTERNS: - Use Page Object Model: create page objects for each page (LoginPage, DashboardPage, etc.). - Create a test user fixture that signs up before tests and cleans up after. - Use data-testid attributes for selecting elements (never rely on CSS classes or text content). - Run tests in isolation — each test should not depend on another test's state. DO NOT: - Modify application code (except adding data-testid attributes) - Test third-party services (mock Stripe) - Write flaky tests that depend on timing (use waitFor and expect patterns)
Replace these variables
| Variable | Replace with |
|---|---|
| [TEST_USER] | Test user credentials for E2E tests |
| [TEST_SUITES] | Features to test (e.g., auth, crud, payments) |
Tips for best results
Use data-testid attributes for element selection — they survive CSS refactors and content changes.
Run 'npx playwright install' to download browser binaries before running tests.
Follow-up prompts
Add visual regression
Add visual regression testing with Playwright screenshots. Compare against baseline screenshots and fail on visual differences.