agentleFS
WST2002WST2002/claude-code-skills/skills/playwright-e2e-tests/SKILL.md

playwright-e2e-tests

Skill4 starsChanged 27 days agoMITView on GitHub

Use when writing, fixing or stabilizing end-to-end or UI tests with Playwright, automating a browser user flow, replacing Cypress or Selenium tests, or setting up Playwright in a web project.

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    No fixed sleeps. Wait on a visible condition or a network response (page.waitForResponse).

    line 47
  2. Distinctive:

    Use the Page Object pattern only when the same page is used in many specs.

    line 49

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Playwright E2E Tests

Overview

End-to-end tests prove that real user journeys work in a real browser. Write few of them, make each one reliable, and locate elements the way users find them.

Method

  1. Setup (if missing): npm init playwright@latest. Configure baseURL, webServer to start the app, trace: "on-first-retry", and the browsers you support in playwright.config.ts.
  2. Pick journeys by risk: sign up / log in, the core purchase or create flow, payments, permissions. One spec file per journey.
  3. Set up state through the API or storage state, not through the UI, except in the test that covers that UI (log in once in a setup project and reuse storageState).
  4. Write steps with user-facing locators and web-first assertions (table below).
  5. Run npx playwright test, then npx playwright test --repeat-each=5 on new tests to catch flakiness. Use npx playwright show-trace on failures.

Locators and assertions

PreferAvoid
page.getByRole("button", { name: "Pay now" })page.locator(".btn-primary:nth-child(2)")
getByLabel("Email"), getByPlaceholder, getByTextXPath, deep CSS chains
getByTestId("cart-total") when no accessible name existsIDs generated at runtime
await expect(locator).toHaveText("₹900") (auto-waits)expect(await locator.textContent()).toBe(...)
await expect(page).toHaveURL(/\/orders\/\d+/)page.waitForTimeout(3000)

Example

import { test, expect } from "@playwright/test";

test("user applies a coupon at checkout", async ({ page }) => {
  await page.goto("/cart");
  await page.getByLabel("Coupon code").fill("SAVE10");
  await page.getByRole("button", { name: "Apply" }).click();
  await expect(page.getByText("Coupon applied")).toBeVisible();
  await expect(page.getByTestId("cart-total")).toHaveText("₹900");
});

Rules

  • Each test is independent: its own data, no order dependence, runs in parallel.
  • No fixed sleeps. Wait on a visible condition or a network response (page.waitForResponse).
  • Mock only third parties you do not control (page.route); keep your own backend real.
  • Use the Page Object pattern only when the same page is used in many specs.
  • Visual comparisons (toHaveScreenshot) only for stable, important screens, with masks for dynamic content.

Common mistakes

  • Testing every edge case end to end; push those down to unit and API tests.
  • Logging in through the UI in every test.
  • Selectors tied to styling classes that change with design updates.
  • Shared test accounts mutated by parallel tests.
  • Retrying flaky tests instead of fixing the wait condition.

Made by Wageesha Tripathi · LinkedIn · Email · More skills

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.