Skip to content
Skills Library
Programming · Testing

writing-playwright-e2e-tests

/writing-playwright-e2e-tests

TSH's standard for Playwright end-to-end tests: mapping acceptance criteria to scenarios, Page Object structure, user-visible locators, auto-waiting instead of manual timeouts, unique test data for parallel runs, mocking only external boundaries, and a bounded debug loop with explicit iteration limits and flake detection. Use when writing, debugging, reviewing or de-flaking E2E tests.

Licence
MIT
Last repository change
27.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
3
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 27.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

TSH's standard for Playwright end-to-end tests: mapping acceptance criteria to scenarios, Page Object structure, user-visible locators, auto-waiting instead of manual timeouts, unique test data for parallel runs, mocking only external boundaries, and a bounded debug loop with explicit iteration limits and flake detection. Use when writing, debugging, reviewing or de-flaking E2E tests.

Original author description

TSH's standard for Playwright end-to-end tests: mapping acceptance criteria to scenarios, Page Object structure, user-visible locators, auto-waiting instead of manual timeouts, unique test data for parallel runs, mocking only external boundaries, and a bounded debug loop with explicit iteration limits and flake detection. Use when writing, debugging, reviewing or de-flaking E2E tests.

How it works

  1. Applicability and Precedence
  2. Non-negotiable Rules
  3. Reference Loading
  4. Map criteria to scenarios first
  5. Naming
  6. Procedure
  7. Output
  8. Anti-Patterns
  9. Related skills in this plugin
Original SKILL.md headings · 132 lines, 968 words
SKILL.md preview
---
name: writing-playwright-e2e-tests
description: "TSH's standard for Playwright end-to-end tests: mapping acceptance criteria to scenarios, Page Object structure, user-visible locators, auto-waiting instead of manual timeouts, unique test data for parallel runs, mocking only external boundaries, and a bounded debug loop with explicit iteration limits and flake detection. Use when writing, debugging, reviewing or de-flaking E2E tests."
when_to_use: "Trigger on: writing E2E or Playwright tests for a feature or acceptance criteria, a flaky test that passes sometimes, a test failing on a timeout or a locator that cannot be found, creating or refactoring Page Objects, deciding what to mock in an E2E test, making a suite CI-ready or headless-safe, reviewing E2E tests before merge, or a plan task whose Definition of Done includes end-to-end coverage."
---

# Writing Playwright E2E Tests

A test earns its place by catching a real bug and never crying wolf. Four properties
carry that: reliable (never flaky), maintainable (Page Objects), fast (parallel-safe),
and meaningful (asserts what a user would notice).

## Applicability and Precedence

**The project's existing test conventions outrank this skill.** Before writing
anything, establish them:

- `playwright.config.ts` — projects, base URL, retries, reporters, viewport
- Existing Page Objects — the directory (`pages/`, `pom/`, `e2e/pages/`) and whether
  they use getters, methods, or fixtures
- Locator strategy already in use, and any `data-testid` convention
- Fixtures and setup files — auth state, seeding, per-test isolation
- The test scripts in `package.json`, and the Playwright version to search docs against

When a `*.plan.md` exists, its Technical Context section is the primary source — it
records conventions already discovered, so do not re-derive them.

## Non-negotiable Rules

| Severity | Rule |
| --- | --- |
| MUST | Use user-visible locators — `getByRole`, `getByLabel`, `getByText`. `getByTestId` only where no user-visible locator is feasible. |
| MUST | Rely on Playwright's auto-waiting assertions. A test that needs a manual delay to pass is a test that will fail in CI. |
| MUST | Generate unique test data per run so tests are parallel-safe — e.g. `test-${Date.now()}-${test.info().parallelIndex}`. |
| MUST | Verify a new or fixed test with **3+ consecutive passes in headless mode** before reporting it done. One green run proves nothing about flake. |
| MUST | Read credentials from environment variables. Never hardcode them, never commit them, never print them. |
| MUST | Mark a test that fails because the *application* is broken as `test.fixme('BUG: <description>')` and report the bug. Never bend the test to make a real defect pass. |
| NEVER | Use `waitForTimeout()`, or `waitForLoadState('networkidle')` — both are flake sources. Wait for a specific element or response instead. |
| NEVER | Use CSS class or XPath selectors that couple the test to implementation detail. |
| NEVER | Let one test depend on state another test left behind. |
| NEVER | Mock the application's own API to make a test pass. Mock only genuinely external third-party boundaries. |

## Reference Loading

| Reference | Load when | Covers |
| --- | --- | --- |
| [Locators, data and mocking](./references/locators-and-anti-flake.md) | Writing any test or Page Object | Locator priority with examples, auto-waiting, test data isolation, what may and may not be mocked |
| [Debugging and the verification loop](./references/debugging-and-verification-loop.md) | A test is failing, flaky, or newly written and unverified | The bounded debug loop, iteration limits, per-error recovery, flake detection, CI readiness |

Read [debugging-and-verification-loop.md](./references/debugging-and-verification-loop.md)
before starting a fix loop — the iteration limits exist to stop an unbounded chase, and
that is the failure mode this skill most often prevents.

## Map criteria to scenarios first

Before writing a line, produce this table:

| Acceptance criterion | Scenario type | Test name |
| :-- | :-- | :-- |
| *from the plan, ticket, or prompt* | Happy / Error / Edge | `should <behavior> when <condition>` |

Then confirm:

- [ ] Every criterion maps to at least one test
- [ ] External boundaries needing a mock are listed
- [ ] Page Objects to create or extend are listed

Coverage is judged against this table, so an unmapped criterion is a gap you name
rather than discover at review.

## Naming

`should <behavior> when <condition>` — `should display an error when login fails`. The
name is the failure message a colleague reads in CI output at 9am; it should say what
broke without opening the file.

## Procedure

1. **Establish context** — the section above, plus the plan's Technical Context.
2. **Map criteria to scenarios** using the table.
3. **Explore the running app** to confirm locators before committing to them. The
   Playwright MCP bundled with this plugin operates on the accessibility tree, which is
   exactly the view `getByRole` resolves against — so what you see there is what your
   locator will match. Requires the dev server running.
4. **Write Page Objects, then tests**, following the project's existing shape.
5. **Run and iterate** under the bounded loop in
   [debugging-and-verification-loop.md](./references/debugging-and-verification-loop.md).
6. **Confirm stability** — 3+ consecutive headless passes.
7. **Check CI readiness** and report.

Look up Playwright API detail with `context7` against the version in `package.json`.
For Playwright specifically, query the library ID `/microsoft/playwright.dev` directly
rather than resolving it first.

## Output

```markdown
## E2E Test Summary

### Coverage
| Criterion | Test | Status |
|---|---|---|

Coverage: X/Y

### Results
| File | Pass | Fail | Flaky | Headless |
|---|---|---|---|---|

### Issues
- BUG: <description> → `test.fixme()`, needs an application fix
- FLAKY: <description> → what was tried, what is still suspected

### Files
```

Report honestly. A suite with two `test.fixme()` markers and a named bug is a better
outcome than a green suite that asserts nothing.

## Anti-Patterns

| Don't | Do |
| :-- | :-- |
| `waitForTimeout(2000)` | Assert on the element or response you are waiting for |
| `.btn-primary`, XPath | `getByRole('button', { name: 'Submit' })` |
| Shared fixture data across tests | Unique data per test run |
| Mock your own API to go green | Mock third-party boundaries only |
| Weaken an assertion to pass | `test.fixme()` and report the bug |
| One green run means done | 3+ consecutive headless passes |
| A test per UI element | A test per user-visible behavior |
| Helpers and Page Objects for tests not yet needed | Only what the current scope requires |

## Related skills in this plugin

- [Auditing accessibility](../auditing-accessibility/SKILL.md) — the accessibility tree
  your role-based locators depend on is the same one an audit examines
Files in this package (3)
  • SKILL.md 7 KB
  • references/debugging-and-verification-loop.md 4 KB
  • references/locators-and-anti-flake.md 5 KB

Versions

The database has no other skills named writing-playwright-e2e-tests.

Database snapshot: 13.11.2026 · package version 3004ec52ce0c (SHA-256 digest of the entire package)

Downloads in the last 30 days: 2 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90e2e-playwright
    Playwright e2e testing: config (parallel, retries=2 in CI, trace on failure), Page Object Model with semantic locators, fixtures for auth state reuse, no hard-coded sleeps, visual regression, accessibility testing, API mocking with route interception. Use when writing e2e tests,…
  • 95e2e-test-writer
    Write comprehensive end-to-end tests using Playwright with page object model pattern. Use when creating browser-based tests for user workflows.
  • 100playwright-testing
    Expert guidance for writing end-to-end tests with Playwright Test framework. Use this skill when writing browser automation tests, creating test suites, working with locators and assertions, mocking network requests, handling authentication, or configuring the Playwright test…
  • 100playwright-automation
    Write production-grade Playwright tests in TypeScript: Page Object Model, fixtures, auto-waiting, user-facing locators, parallel execution, CI integration, sharding, and installed-version checks. Includes an explicit "do not" list for AI agents. Use when: "Playwright," "write…
  • 100playwright-e2e-testing
    Write, fix, or review Playwright end-to-end tests, especially for Next.js apps - locators, auth via storageState, flaky waits, server-side fetch mocking, CI against a production build. Use for *.spec.ts / e2e/ / playwright.config changes or flaky browser tests. For unit and…
  • 100playwright
    Playwright E2E testing framework. Covers browser automation, assertions, and test generation. Use for end-to-end testing. USE WHEN: user mentions "playwright", "e2e test", "browser test", "end-to-end", asks about "page.goto", "page.click", "locators", "cross-browser testing",…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.