e2e-spec-rules
Skill0 starsChanged 23 days agoMITView on GitHub
The rules every Playwright E2E spec in this skill set follows, covering self-contained tests, user-facing locators, exact web-first assertions, and the patterns that disqualify a spec. Use when writing, fixing or reviewing a Playwright E2E spec, and whenever e2e-plan or e2e-repro says to follow the spec rules. States the rules and nothing else, since e2e-plan writes the spec and e2e-assess reviews it.
- Reads credentials
In this repository8 other files it gives its agents.
- e2e-assessSkill
- e2e-planSkill
- e2e-pruneSkill
- e2e-release-confidenceSkill
- e2e-reproSkill
- e2e-setupSkill
- e2e-triageSkill
- release-canarySkill
The file
Files
e2e-spec-rules
Rules for a spec that fails when the feature breaks and for no other reason. ENV is the environment file .e2e/e2e-env.md.
- Self-contained. Every test reads top to bottom as the user's journey: reset (per ENV),
gotothe first page, log in through the UI where the scenario has an account, then reach every later page the way the user does: click the header link, the record's name, the "Proceed to checkout" link.gotoonly for the first page of a test; a secondgotoskips the navigation the user would have done and tests a route the app never shows. Wait on each page's ready signal (per ENV), then the steps. All of it inline, in every test, as plain Playwright steps. NobeforeEach, no helper functions, no custom fixtures, norequestfixture:async ({ page })is the only signature. Repetition between tests is correct here; a reader of one test needs nothing else. - Locators.
getByRole,getByLabel,getByText;getByTestIdonly when nothing user-facing is unique. Scope with.filter({ has })or chain from a row or dialog. No CSS, no.locator(...). A chain through generic text (the "1" inside the Cart link) is a guess, and a chain throughgetByRole("paragraph")orgetByRole("strong")is DOM structure, not something the user names; there the testid from ENV is the locator. A dropdown isgetByRole("combobox", { name })by its label text, set withselectOption({ label })by the option text the user reads, never by value. - Ambiguity. A locator that matches 0 or 2+ elements is fixed from a fresh live snapshot: scoped (
dialog.getByRole("alert")) or named (getByRole("status", { name: ... })). A name or text matches as a case-insensitive substring, so{ name: "Save" }also matches "Save draft"; two matches of that kind are fixed with{ name: "Save", exact: true }. A label that matches two fields (login and register forms on one page) means the testid from ENV. Never.first(), never a try/catch. - Ready signal. Asserted like anything else:
await expect(page.getByTestId("cart-page")).toHaveAttribute("data-state", "ready"). - Rows. Found by the name the user sees (
getByRole("row", { name: "CI pipeline" })), never by a seed id. A record's own page is reached the way the user reaches it, by clicking its name, never bygotowith a seed id in the path (goto("/products/prod-001")). The id for apage.requestURL comes from a GET of the list, found by the same name (keys.find(k => k.name === "CI pipeline").id), never typed from seed data. - Assertions. Web-first only (
await expect(locator).toBeVisible(),toHaveCount(0),toHaveURL), on the exact element with the exact value:toHaveText("paid"), sincetoContainText("paid")also holds for "unpaid", and atoHaveCount(1)on generic text proves nothing.toContainTextis allowed only for a message with a variable part, never for a plan name, a status, a date or an amount. A URL is asserted as the exact string,toHaveURL("/account"), never a regex. - Transient text (toast, spinner, "Saving…"). Assert it only when the ticket claims it. To wait for an action, use the durable state it produces (the cart count, the new row).
- Absence.
await expect(row.getByRole("button", { name: "Remove" })).toHaveCount(0)scoped to the row, never an unscopedgetByText. A hidden element keeps its text, andtoHaveTextpasses on text the user cannot see; what the ticket calls hidden, gone or empty is asserted withtoBeHidden()ortoHaveCount(0)on that element, never with its leftover text (a badge reading "0" underhiddenis hidden, not "0"). - State that must persist or stay unchanged. A committed state change the ticket says persists (an item added, a member removed, a plan switched): assert the new state as the page shows it,
reload, wait for ready, assert it again. The first proves the UI reacted, the second proves the server kept it. Unchanged state after an error gets the same pair. One reload per committed change, on the page that shows it; never on a page with a form in progress, and never after a sign-in or a navigation, which changed nothing the ticket claims. - Passwords.
process.env.E2E_PASSWORD_<NAME>, the variable ENV names. Never the literal value. - URLs. Relative everywhere,
goto("/settings")andpage.request.delete("/api/...")alike. The base URL lives in the Playwright config, never in the spec.
Disqualified, each one on its own: waitForTimeout, if (await x.isVisible()), .catch(() => ...) on a locator, regex locators guessing the UI (/log ?in|sign ?in/), page.on("dialog") for a dialog never seen live, .first()/.last()/.nth() to silence ambiguity, .or() to hedge between two guesses (.and() and .filter() narrow and are fine).
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
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.

