playwright-testing
/playwright-testing
Write and maintain end-to-end tests with Playwright. Use when someone asks to "add e2e tests", "test my web app", "set up Playwright", "write browser tests", "test login flow", "visual regression testing", "test across browsers", or "automate UI testing". Covers test setup, page objects, authentication, API mocking, visual comparisons, and CI integration.
- Author
- TerminalSkills ↗
- Repository
- skills ↗
- Licence
- Apache-2.0
- Last repository change
- 25.10.2026
Assessment and security
- Files in this package
- 2
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 3
No signals detected. Repository changed on 25.10.2026, without references to retired models or APIs.
Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.
What it does and when to use it
Write and maintain end-to-end tests with Playwright. Use when someone asks to "add e2e tests", "test my web app", "set up Playwright", "write browser tests", "test login flow", "visual regression testing", "test across browsers", or "automate UI testing". Covers test setup, page objects, authentication, API mocking, visual comparisons, and CI integration.
Triggers from the description
Original author description
Write and maintain end-to-end tests with Playwright. Use when someone asks to "add e2e tests", "test my web app", "set up Playwright", "write browser tests", "test login flow", "visual regression testing", "test across browsers", or "automate UI testing". Covers test setup, page objects, authentication, API mocking, visual comparisons, and CI integration.
How it works
- Overview
- Instructions
- Examples
- Guidelines
SKILL.md preview
---
name: playwright-testing
description: >-
Write and maintain end-to-end tests with Playwright. Use when someone asks to
"add e2e tests", "test my web app", "set up Playwright", "write browser
tests", "test login flow", "visual regression testing", "test across
browsers", or "automate UI testing". Covers test setup, page objects,
authentication, API mocking, visual comparisons, and CI integration.
license: Apache-2.0
compatibility: 'Playwright 1.64 (needs Node.js 20+). Supports Chromium, Firefox, WebKit.'
metadata:
author: terminal-skills
version: 1.1.0
category: development
tags: "playwright, testing, e2e, browser-testing, automation"
---
# Playwright Testing
## Overview
This skill helps AI agents write reliable end-to-end tests using Playwright. It covers project setup, writing tests with auto-waiting locators, page object patterns, authentication handling, API mocking, visual regression, accessibility testing, and CI/CD integration.
## Instructions
### Step 1: Project Setup
```bash
npm init playwright@latest
# Or add to an existing project:
npm install -D @playwright/test && npx playwright install
# On Linux CI or a fresh container also pass --with-deps for system libraries
```
```typescript
// playwright.config.ts
import { defineConfig, devices } from '@playwright/test';
export default defineConfig({
testDir: './tests',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: [['html', { open: 'never' }], ['junit', { outputFile: 'test-results/junit.xml' }]],
use: {
baseURL: process.env.BASE_URL || 'http://localhost:3000',
trace: 'on-first-retry',
screenshot: 'only-on-failure',
},
projects: [
{ name: 'chromium', use: { ...devices['Desktop Chrome'] } },
{ name: 'firefox', use: { ...devices['Desktop Firefox'] } },
{ name: 'webkit', use: { ...devices['Desktop Safari'] } },
{ name: 'mobile-chrome', use: { ...devices['Pixel 5'] } },
],
webServer: {
command: 'npm run dev',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
},
});
```
### Step 2: Write Tests
```typescript
import { test, expect } from '@playwright/test';
test.describe('Homepage', () => {
test('displays hero and navigates to features', async ({ page }) => {
await page.goto('/');
await expect(page.getByRole('heading', { name: /welcome/i })).toBeVisible();
await page.getByRole('link', { name: 'View Features' }).click();
await expect(page).toHaveURL(/.*features/);
});
test('shows search results', async ({ page }) => {
await page.goto('/');
await page.getByPlaceholder('Search...').fill('playwright');
await page.getByPlaceholder('Search...').press('Enter');
await expect(page.getByTestId('search-results')).toBeVisible();
await expect(page.getByTestId('search-result-item')).toHaveCount(10);
});
});
```
### Step 3: Authentication Pattern
```typescript
// tests/auth.setup.ts — authenticate once, reuse across tests
import { test as setup, expect } from '@playwright/test';
import path from 'path';
// Keep the saved state out of git: add playwright/.auth to .gitignore
const authFile = path.join(__dirname, '../playwright/.auth/user.json');
setup('authenticate', async ({ page }) => {
await page.goto('/login');
await page.getByLabel('Email').fill(process.env.E2E_EMAIL!);
await page.getByLabel('Password').fill(process.env.E2E_PASSWORD!);
await page.getByRole('button', { name: 'Sign in' }).click();
await expect(page).toHaveURL('/dashboard');
await page.context().storageState({ path: authFile });
});
// Run this project first, then reuse the saved state; in playwright.config.ts:
// projects: [
// { name: 'setup', testMatch: /.*\.setup\.ts/ },
// { name: 'chromium', use: { ...devices['Desktop Chrome'], storageState: 'playwright/.auth/user.json' }, dependencies: ['setup'] },
// ]
```
### Step 4: Page Object Pattern
```typescript
// tests/pages/login.page.ts
import { Page, Locator, expect } from '@playwright/test';
export class LoginPage {
readonly emailInput: Locator;
readonly passwordInput: Locator;
readonly submitButton: Locator;
readonly errorMessage: Locator;
constructor(private page: Page) {
this.emailInput = page.getByLabel('Email');
this.passwordInput = page.getByLabel('Password');
this.submitButton = page.getByRole('button', { name: 'Sign in' });
this.errorMessage = page.getByRole('alert');
}
async goto() { await this.page.goto('/login'); }
async login(email: string, password: string) {
await this.emailInput.fill(email);
await this.passwordInput.fill(password);
await this.submitButton.click();
}
async expectError(msg: string) { await expect(this.errorMessage).toContainText(msg); }
}
// tests/login.spec.ts
import { test, expect } from '@playwright/test';
import { LoginPage } from './pages/login.page';
test.describe('Login', () => {
let loginPage: LoginPage;
test.beforeEach(async ({ page }) => { loginPage = new LoginPage(page); await loginPage.goto(); });
test('successful login redirects to dashboard', async ({ page }) => {
await loginPage.login(process.env.E2E_EMAIL!, process.env.E2E_PASSWORD!);
await expect(page).toHaveURL('/dashboard');
});
test('invalid credentials show error', async () => {
await loginPage.login('nobody@shopfront.dev', 'not-the-password');
await loginPage.expectError('Invalid email or password');
});
});
```
### Step 5: API Mocking
```typescript
test('shows error state when API fails', async ({ page }) => {
await page.route('**/api/projects', (route) => route.fulfill({
status: 500, contentType: 'application/json',
body: JSON.stringify({ error: 'Internal server error' }),
}));
await page.goto('/dashboard');
await expect(page.getByText('Failed to load projects')).toBeVisible();
});
test('modify API response for premium features', async ({ page }) => {
await page.route('**/api/user', async (route) => {
const response = await route.fetch();
const json = await response.json();
json.plan = 'enterprise';
await route.fulfill({ response, json });
});
await page.goto('/settings');
await expect(page.getByText('Enterprise Plan')).toBeVisible();
});
```
### Step 6: Visual & Accessibility Testing
```typescript
test('homepage visual regression', async ({ page }) => {
await page.goto('/');
await expect(page).toHaveScreenshot('homepage.png', { fullPage: true, maxDiffPixelRatio: 0.01 });
});
// First run writes the baseline; update with: npx playwright test --update-snapshots
// Baselines are per browser and OS (homepage-chromium-linux.png), so generate them on the OS that runs CI
// npm install -D @axe-core/playwright
import AxeBuilder from '@axe-core/playwright';
test('no accessibility violations', async ({ page }) => {
await page.goto('/');
const results = await new AxeBuilder({ page }).withTags(['wcag2a', 'wcag2aa']).analyze();
expect(results.violations).toEqual([]);
});
```
### Step 7: CI Integration
```yaml
# .github/workflows/e2e.yml
name: E2E Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with: { node-version: lts/*, cache: npm }
- run: npm ci
- run: npx playwright install --with-deps
- run: npx playwright test
- uses: actions/upload-artifact@v7
if: always()
with: { name: playwright-report, path: playwright-report/, retention-days: 30 }
```
### Useful Commands
```bash
npx playwright test # Run all tests
npx playwright test tests/login.spec.ts # Specific file
npx playwright test --headed # See browser
npx playwright test --project=chromium # Specific browser
npx playwright test --debug # Step-through debugger
npx playwright codegen http://localhost:3000 # Record actions
npx playwright show-report # View HTML report
```
## Examples
### Example 1: Add e2e tests for a login flow with page objects
**User prompt:** "Write Playwright tests for our login page that test successful login, invalid credentials, and form validation, using the page object pattern."
The agent will:
1. Create `tests/pages/login.page.ts` with locators for email, password, submit button, and error message using role-based selectors (`getByLabel`, `getByRole`)
2. Add `goto()`, `login()`, and `expectError()` methods to the page object
3. Write three tests: successful login verifying redirect to `/dashboard`, invalid credentials checking the error alert, and empty form submission checking validation messages
4. Set up `beforeEach` to instantiate the page object and navigate to `/login`
### Example 2: Mock API responses to test error and empty states
**User prompt:** "Add tests for our dashboard that verify it handles API errors gracefully and shows an empty state when there are no projects."
The agent will:
1. Use `page.route('**/api/projects', ...)` to intercept the API call
2. For the error test: fulfill with status 500 and verify the "Failed to load projects" message and Retry button appear
3. For the empty test: fulfill with status 200 and an empty projects array, then verify the "No projects yet" empty state is shown
4. Both tests run in isolation without needing a real backend, making them fast and reliable in CI
## Guidelines
- Use role-based locators (`getByRole`, `getByLabel`, `getByText`) over CSS selectors — more resilient to DOM changes
- Add `data-testid` attributes only when no semantic locator works
- Never use `page.waitForTimeout()` — use auto-waiting locators or `expect` with timeout
- Run auth setup once and share state across tests via `storageState`
- Use page objects for complex pages to keep tests readable
- Mock external APIs in tests — test UI behavior, not third-party services
- Run tests in parallel (`fullyParallel: true`) for speed
- Capture traces on first retry — invaluable for debugging flaky tests in CI
- Use `webServer` config to auto-start your dev server during tests
- Keep visual snapshots in version control and review changes in PRs
- Keep credentials in environment variables (`E2E_EMAIL`, `E2E_PASSWORD`) and never commit `playwright/.auth`
Files in this package (2)
- SKILL.md 10 KB
- _scores.json 1 KB
Versions
| Repository | Score | Licence |
|---|---|---|
| This page · TerminalSkills/skills | 100 | Apache-2.0 |
| marmelab/atomic-crm | 100 | MIT |
| event4u-app/agent-config | 100 | MIT |
| arozumenko/sdlc-skills | 100 | MIT |
| arozumenko/sdlc-skills | 100 | MIT |
| laurigates/claude-plugins | 100 | MIT |
| aehrc/pathling | 100 | MIT |
| testland/qa | 100 | MIT |
| SkillMedev/skills | 100 | MIT |
Database snapshot: 13.11.2026 · package version c1b138fa8f79 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.
Similar skills
- 100playwright-expert
Use when writing E2E tests with Playwright, setting up test infrastructure, or debugging flaky browser tests. Invoke to write test scripts, create page objects, configure test fixtures, set up reporters, add CI integration, implement API mocking, or perform visual regression… - 100playwright-expert
Use when writing E2E tests with Playwright, setting up test infrastructure, or debugging flaky browser tests. Invoke to write test scripts, create page objects, configure test fixtures, set up reporters, add CI integration, implement API mocking, or perform visual regression… - 100playwright-expert
Use when writing E2E tests with Playwright, setting up test infrastructure, or debugging flaky browser tests. Invoke to write test scripts, create page objects, configure test fixtures, set up reporters, add CI integration, implement API mocking, or perform visual regression… - 95playwright-e2e-automation
Master enterprise Playwright end-to-end (E2E) automation, Page Object Model (POM) architecture, cross-browser testing, network mocking, visual regression testing, and CI pipeline integrations. Trigger when writing Playwright tests, automating web UI E2E flows, or configuring… - 100playwright
Write, run, and maintain reliable end-to-end tests with Playwright. Use for test generation, CI integration, trace debugging, and cross-browser validation. - 100playwright-e2e-testing
Author and maintain versioned Playwright (@playwright/test) TypeScript UI specs for browser user flows. Use when asked to create, run, debug, or refactor E2E tests, form/navigation/auth flows, responsive checks, UI mocking, fixtures, Page Objects, or visual comparisons. Use…