Skip to main content
skill CX Codex

Playwright · mindrally — Claude Code skill: end-to-end testing for web apps

Skill for automating E2E testing of web applications in TypeScript and JavaScript. Teaches agents to write tests following best practices: resilient locators, web-first assertions, no hardcoded timeouts.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add Mindrally/skills --skill playwright -a claude-code
Open on GitHub

What playwright does

The skill covers methodology and code patterns for reliable E2E tests with Playwright. It addresses test structure using fixtures, element location strategies (getByRole, getByLabel, getByTestId), and web-first assertions that automatically wait and retry. Includes configuration for running tests across Chrome, Firefox, and mobile devices.

Agents learn to build tests that track critical user journeys while avoiding brittle selectors and flaky timeouts. Helpers manage test state through beforeEach and afterEach hooks, and extraction of reusable logic reduces duplication.

What it helps with

  • write end-to-end tests for a web app with resilient locators
  • eliminate flaky tests caused by hardcoded waits and unstable selectors
  • configure parallel test runs across multiple browsers
  • capture screenshots and traces only on failure
  • verify login flows, navigation, and critical business processes

Example prompts for the agent

  • Write an E2E test for user login with Playwright, using getByLabel for form fields and getByRole for the submit button
  • Set up a Playwright configuration to run tests in Chrome, Firefox, and on mobile, with screenshots on failure
  • Refactor an old test from XPath selectors to getByRole and remove all waitForTimeout calls

How to install playwright

1Skills CLI (Vercel)

npx skills add Mindrally/skills --skill playwright -a claude-code

2Manually: put the files in place

~/.claude/skills/playwright/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/playwright/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about playwright

How do I install the Playwright skill in Claude Code?

Run npx skills add Mindrally/skills --skill playwright -a claude-code. The skill will load into ~/.claude/skills/playwright/SKILL.md and become available to the agent.

Why would a developer use this skill?

It teaches the agent to write E2E tests using best practices: semantic locators instead of fragile CSS selectors, web-first assertions instead of hardcoded waits, and configuration to run across different browsers.

What locator strategies does the skill recommend?

Prioritize getByRole for accessibility, getByLabel for inputs, getByText for visible text, getByTestId when data-testid exists, and getByPlaceholder. Avoid CSS classes like .btn-primary.

Source text

SKILL.md · Apache-2.0
---
name: playwright
description: Playwright end-to-end testing best practices for web applications, covering test design, locator strategies, and assertion patterns.
metadata:
  maintainer: Mindrally
  source: https://github.com/Mindrally/skills
---

# Playwright Testing Best Practices

You are a Senior QA Automation Engineer expert in TypeScript, JavaScript, and Playwright end-to-end testing.

## Test Design Principles

### Test Structure
- Create descriptive test names that clearly explain expected behavior
- Use Playwright fixtures (`test`, `page`, `expect`) for test isolation
- Implement `test.beforeEach` and `test.afterEach` for clean state management
- Keep tests DRY by extracting reusable logic into helper functions

```typescript
import { test, expect } from '@playwright/test';

test.describe('User Authentication', () => {
  test.beforeEach(async ({ page }) => {
    await page.goto('/login');
  });

  test('should login successfully with valid credentials', async ({ page }) => {
    await page.getByLabel('Email').fill('[email protected]');
    await page.getByLabel('Password').fill('password123');
    await page.getByRole('button', { name: 'Sign In' }).click();

    await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();
  });
});
```

## Locator Strategy

### Recommended Locators
- `page.getByRole()` - Best for accessibility and user perspective
- `page.getByLabel()` - For form inputs with labels
- `page.getByText()` - For elements with visible text
- `page.getByTestId()` - When `data-testid` attributes exist
- `page.getByPlaceholder()` - For inputs with placeholder text

```typescript
// Recommended
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByLabel('Email address').fill('[email protected]');

// Avoid
await page.locator('.btn-primary').click();
```

## Assertions and Waits

### Web-First Assertions
Prefer web-first assertions that automatically wait and retry:

- `toBeVisible()` - Element is visible
- `toHaveText()` - Element has specific text
- `toHaveValue()` - Input has specific value
- `toHaveURL()` - Page URL assertion

```typescript
// Recommended - web-first assertions
await expect(page.getByRole('alert')).toBeVisible();
await expect(page).toHaveURL('/dashboard');

// Avoid - hardcoded timeouts
await page.waitForTimeout(5000); // Never do this
```

### Waiting Best Practices
- Avoid hardcoded timeouts
- Use `page.waitForLoadState()` for navigation
- Use `page.waitForResponse()` for API calls

## Configuration

```typescript
import { defineConfig, devices } from '@playwright/test';

export default defineConfig({
  testDir: './tests',
  fullyParallel: true,
  retries: process.env.CI ? 2 : 0,
  use: {
    baseURL: '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: 'mobile', use: { ...devices['iPhone 13'] } },
  ],
});
```

## Best Practices
- Focus on critical user paths reflecting real behavior
- Keep tests independent and deterministic
- Add JSDoc comments for helper functions
- Implement proper error handling and logging

© Mindrally · Apache-2.0 · Mindrally/skills

Similar skills

All skills for Testing and QA →

playwright by other authors comes first.

playwright PyModel A Playwright skill for Next.js with 45 rules across 8 categories, from test architecture to CI debugging. Useful when tests fail at random. CX Codex +1 485installs playwright secondsky A Playwright skill for browser automation and end-to-end testing. It finds your running dev server and writes the test script for the task. CX Codex +1 1,000installs playwright bobmatnyc A Playwright skill that guides the agent through writing end-to-end tests: locators, auto-wait, cross-browser runs. Useful when user flows need test coverage. CX Codex +1 879installs playwright oakoss A skill that teaches your agent the Playwright API: locators, assertions, screenshots and PDFs, stealth mode, authenticated sessions, error fixes. CX Codex +1 452installs improve-codebase-architecture Matt Pocock This skill scans a codebase for architectural friction, then builds a visual HTML report with refactoring candidates. Use it before a deeper architecture review. 1,163,035installs design-taste-frontend Leonxlnx This skill directs the design of public pages and work screens, then checks the result in a browser through screenshots. Use it when an interface feels generic or unfinished. CX Codex +1 678,700installs tdd Matt Pocock Guides the red-green TDD loop: ensures tests are written first, keep them at public interfaces, and avoid coupling to implementation details. 1,141,062installs skill-creator official anthropics Creates and refines skills, then tests them with prompts, evaluations, and performance checks. 414,180installs agent-browser vercel-labs A CLI skill for browser control: it opens pages, fills forms, clicks buttons, and tests web apps. Use it when an agent needs to act inside a website. CX Codex +1 1,200,000installs prototype Matt Pocock Creates throwaway prototypes for checking state logic or exploring UI before committing the decision to the main codebase. 986,201installs

From the same set236

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor