Skip to main content
skill CX Codex

playwright · pymodel — Claude Code skill: Next.js E2E tests, flaky fixes

A Playwright skill for Next.js with 45 rules across 8 categories, from test architecture to CI debugging. Useful when tests fail at random.

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

What playwright does

The skill splits into 8 categories by priority: test architecture and locators are critical, waiting and auth are high, mocking and Next.js integration sit in the middle, performance and CI debugging lower. Every rule has a prefix (arch-, loc-, wait-, auth-, mock-, next-, perf-, debug-) and its own file at references/<rule-id>.md with the reasoning plus incorrect and correct code samples.

In practice you run two commands from the project root: npx -y @pymodel/react-frontend-skills detect compares installed versions against target ones, and npx -y @pymodel/react-frontend-skills scan --skill playwright lists deprecated APIs with rule IDs. Then you open the rule files that match your task and each scan hit.

The rules assume Next.js. Hydration, Server Components, App Router navigation and Server Actions each get their own entries, so on a different framework those parts go unused. Author is PyModel, MIT licensed.

What it helps with

  • find out why a test passes locally and fails in CI
  • swap CSS selectors for role-based locators
  • reuse authentication state across tests
  • mock API responses for deterministic runs
  • shard a large test suite

Example prompts for the agent

  • Check my Playwright tests for flakiness and apply the playwright skill rules
  • Rewrite the selectors in this test to use getByRole and getByLabel
  • Set up storage state for auth in my Next.js tests

How to install playwright

1Skills CLI (Vercel)

npx skills add PyModel/react-frontend-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 playwright in Claude?

Run npx skills add PyModel/react-frontend-skills --skill playwright -a claude-code. The skill file lands at ~/.claude/skills/playwright/SKILL.md.

What does the playwright skill do?

It supplies 45 rules for writing and debugging Playwright E2E tests in Next.js: locators, waiting, auth, mocking, performance and CI work.

What should I run before using the skill?

From the project root, run npx -y @pymodel/react-frontend-skills detect first, then npx -y @pymodel/react-frontend-skills scan --skill playwright to get deprecated APIs and the rule IDs worth reading.

Source text

SKILL.md · MIT
---
name: playwright
description: Playwright end-to-end tests and flaky-test fixes.
---

# Playwright + Next.js Testing Best Practices

Comprehensive testing optimization guide for Playwright with Next.js applications. Contains 45 rules across 8 categories, prioritized by impact to guide reliable, fast, and maintainable E2E tests.

## When to Apply

Reference these guidelines when:
- Writing new Playwright tests for Next.js apps
- Debugging flaky or failing tests
- Optimizing test execution speed
- Setting up authentication state reuse
- Configuring CI/CD pipelines for testing
- Testing Server Components and App Router features
- Reviewing test code for reliability issues

## Rule Categories by Priority

| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Test Architecture | CRITICAL | `arch-` |
| 2 | Selectors & Locators | CRITICAL | `loc-` |
| 3 | Waiting & Assertions | HIGH | `wait-` |
| 4 | Authentication & State | HIGH | `auth-` |
| 5 | Mocking & Network | MEDIUM-HIGH | `mock-` |
| 6 | Next.js Integration | MEDIUM | `next-` |
| 7 | Performance & Speed | MEDIUM | `perf-` |
| 8 | Debugging & CI | LOW-MEDIUM | `debug-` |

## Quick Reference

### 1. Test Architecture (CRITICAL)

- [`arch-test-isolation`](references/arch-test-isolation.md) - Use fresh browser context for each test
- [`arch-parallel-execution`](references/arch-parallel-execution.md) - Enable parallel test execution
- [`arch-page-object-model`](references/arch-page-object-model.md) - Use Page Object Model for complex pages
- [`arch-fixtures`](references/arch-fixtures.md) - Use fixtures for shared setup
- [`arch-test-production`](references/arch-test-production.md) - Test against production builds
- [`arch-cleanup-state`](references/arch-cleanup-state.md) - Clean up test state after each test

### 2. Selectors & Locators (CRITICAL)

- [`loc-role-selectors`](references/loc-role-selectors.md) - Use role-based selectors over CSS
- [`loc-data-testid`](references/loc-data-testid.md) - Use data-testid for dynamic elements
- [`loc-label-selectors`](references/loc-label-selectors.md) - Use getByLabel for form inputs
- [`loc-text-selectors`](references/loc-text-selectors.md) - Use getByText for static content
- [`loc-avoid-xpath`](references/loc-avoid-xpath.md) - Avoid XPath selectors
- [`loc-chained-locators`](references/loc-chained-locators.md) - Chain locators for specificity
- [`loc-placeholder-selector`](references/loc-placeholder-selector.md) - Use getByPlaceholder sparingly
- [`loc-frame-locator`](references/loc-frame-locator.md) - Locate elements inside iframes with frameLocator

### 3. Waiting & Assertions (HIGH)

- [`wait-web-first-assertions`](references/wait-web-first-assertions.md) - Use web-first assertions
- [`assert-aria-snapshots`](references/assert-aria-snapshots.md) - Assert accessibility structure with aria snapshots
- [`wait-avoid-hard-waits`](references/wait-avoid-hard-waits.md) - Avoid hard waits
- [`wait-network-idle`](references/wait-network-idle.md) - Wait for observable readiness, not network idle
- [`wait-action-retries`](references/wait-action-retries.md) - Let actions auto-wait before interacting
- [`wait-soft-assertions`](references/wait-soft-assertions.md) - Use soft assertions for non-critical checks
- [`wait-custom-timeout`](references/wait-custom-timeout.md) - Configure timeouts appropriately

### 4. Authentication & State (HIGH)

- [`auth-storage-state`](references/auth-storage-state.md) - Reuse authentication with storage state
- [`auth-multiple-roles`](references/auth-multiple-roles.md) - Use separate storage states for different roles
- [`auth-session-storage`](references/auth-session-storage.md) - Handle session storage for auth
- [`auth-api-login`](references/auth-api-login.md) - Use API login for faster auth setup
- [`auth-parallel-workers`](references/auth-parallel-workers.md) - Use worker-scoped auth for parallel tests

### 5. Mocking & Network (MEDIUM-HIGH)

- [`mock-api-responses`](references/mock-api-responses.md) - Mock API responses for deterministic tests
- [`mock-intercept-modify`](references/mock-intercept-modify.md) - Intercept and modify real responses
- [`mock-har-files`](references/mock-har-files.md) - Use HAR files for complex mock scenarios
- [`mock-abort-requests`](references/mock-abort-requests.md) - Abort unnecessary requests
- [`mock-network-conditions`](references/mock-network-conditions.md) - Simulate network conditions

### 6. Next.js Integration (MEDIUM)

- [`next-wait-hydration`](references/next-wait-hydration.md) - Wait for hydration before interacting
- [`next-server-components`](references/next-server-components.md) - Test server components correctly
- [`next-app-router-navigation`](references/next-app-router-navigation.md) - Test App Router navigation patterns
- [`next-server-actions`](references/next-server-actions.md) - Test server actions end-to-end
- [`next-baseurl-config`](references/next-baseurl-config.md) - Configure baseURL for clean navigation

### 7. Performance & Speed (MEDIUM)

- [`perf-sharding`](references/perf-sharding.md) - Use sharding for large test suites
- [`perf-headless-ci`](references/perf-headless-ci.md) - Use headless mode in CI
- [`perf-browser-selection`](references/perf-browser-selection.md) - Select browsers strategically
- [`perf-reuse-server`](references/perf-reuse-server.md) - Reuse a matching local server when safe
- [`perf-retries`](references/perf-retries.md) - Use retries to detect and diagnose flakiness

### 8. Debugging & CI (LOW-MEDIUM)

- [`debug-trace-viewer`](references/debug-trace-viewer.md) - Use trace viewer for failed tests
- [`debug-screenshots-videos`](references/debug-screenshots-videos.md) - Capture screenshots and videos on failure
- [`debug-inspector`](references/debug-inspector.md) - Use Playwright Inspector for interactive debugging
- [`debug-ci-reporters`](references/debug-ci-reporters.md) - Configure reporters for CI integration

## How to Use

Run in the project root first:

```bash
npx -y @pymodel/react-frontend-skills detect                   # installed vs. targeted versions
npx -y @pymodel/react-frontend-skills scan --skill playwright  # deprecated APIs → rule IDs
```

Read `references/<rule-id>.md` for each rule above that matches the task and for each `scan` hit: why it matters, then incorrect vs. correct code.

© PyModel · MIT · PyModel/react-frontend-skills

Similar skills

Everything for Testing and QA →

playwright by other authors comes first.

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 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 playwright-core testdino-hq Provides battle-tested Playwright patterns for E2E, API, and component tests in TypeScript and JavaScript. Helps debug flaky runs, configure fixtures, and structure test suites. CX Codex +1 778installs playwright-best-practices currents.dev A reference skill for Playwright test architecture, locator design, and Page Object Model. Helps debug flaky runs, mock network requests, and audit accessibility. CX Codex +1 98,500installs fix Alireza Rezvani Sorts a failing or flaky Playwright test into a category, applies the matching fix, then proves it holds. Useful when a test fails in CI but passes locally. 1,638installs playwright-skill lackeyjb Write and run Playwright scripts directly in your IDE. Auto-detects dev servers, takes screenshots, checks responsive layouts, tests login flows, and validates web functionality. CX Codex +1 6,900installs hyva-playwright-test hyva-themes Guides writing Playwright end-to-end tests for Hyvä Magento storefronts using Alpine.js. It resolves locator conflicts caused by hidden DOM elements. CX Codex +1 1,300installs e2e-playwright-testing Agent Skills Contributors A skill that guides the agent through writing Playwright E2E tests: locators, auth reuse, forms, assertions and CI config. CX Codex +1 796installs

From the same set9

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