Write end-to-end tests using Playwright or Cypress
✓Works with OpenClaudeYou are an end-to-end test automation engineer. The user wants to write robust, maintainable E2E tests using Playwright or Cypress that validate complete user workflows across a web application.
What to check first
playwright.config.tsorcypress.config.ts— verify base URL, browser targets, and timeout settingspackage.json— confirm@playwright/testorcypressis installed with correct version- Existing test file structure in
tests/orcypress/e2e/directory - Browser requirements — Playwright needs Chromium/Firefox/WebKit; Cypress typically uses Chrome/Electron
Steps
- Install dependencies: run
npm install --save-dev @playwright/test(Playwright) ornpm install --save-dev cypress(Cypress) - Initialize config: run
npx playwright initornpx cypress opento generate default configuration files with browser and base URL settings - Create a page object model file (e.g.,
pages/LoginPage.ts) to encapsulate selectors and user interactions — this keeps tests DRY and maintainable - Write your first test file using
test()blocks and assertions — import page objects and chain actions likepage.goto(),page.fill(),page.click() - Add
awaitkeywords before all async operations (goto,click,fill,waitForSelector) to prevent race conditions - Implement intelligent waits with
page.waitForLoadState('networkidle')orcy.intercept()for Cypress instead of hardsleep()calls - Run tests headless with
npx playwright testornpx cypress run --headless; use--headed --debugflags for local development and debugging - Set up CI/CD by adding a GitHub Actions workflow (
.github/workflows/e2e.yml) that runs tests on every PR against your staging environment
Code
// Playwright example: pages/LoginPage.ts (Page Object Model)
import { Page, expect } from '@playwright/test';
export class LoginPage {
constructor(private page: Page) {}
async goto() {
await this.page.goto('/login');
await this.page.waitForLoadState('networkidle');
}
async fillEmail(email: string) {
await this.page.fill('input[type="email"]', email);
}
async fillPassword(password: string) {
await this.page.fill('input[type="password"]', password);
}
async clickLoginButton() {
await this.page.click('button:has-text("Login")');
}
async getErrorMessage() {
return await this.page.textContent('[data-testid="error-message"]');
}
async loginAs(email: string, password: string) {
await this.fillEmail(email);
await this.fillPassword(password);
await
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Testing Skills
Other Claude Code skills in the same category — free to download.
Unit Test Generator
Generate unit tests for any function or class
Test Coverage Analyzer
Analyze test coverage gaps and suggest tests to write
Mock Generator
Generate mocks, stubs, and fakes for dependencies
Snapshot Test Creator
Create snapshot tests for UI components
Test Data Factory
Create test data factories and fixtures
API Test Suite
Generate API test suites for REST endpoints
Mutation Testing Setup
Set up mutation testing to verify test quality
Test Refactorer
Refactor tests to follow AAA pattern and best practices
Want a Testing skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.