agentleFS
ambroselittleambroselittle/agent-skills/skills/author-e2e/SKILL.md

author-e2e

Skill0 starsChanged 13 days agoMITView on GitHub

Author Playwright E2E tests from scenario files or feature descriptions. Generates .scenario.md files, page objects, and test files following Page Object Model and flakiness best practices.

The file

Show its rules and text

We split this skill into the rules it gives an agent

23 rules. About 0 are common, 16 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈16

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Keep scenarios focused — 3-8 steps each

    line 51
  2. Distinctive:

    When given a description instead of a file:

    line 55
  3. Very specific:

    Write one .scenario.md per flow

    line 57
  4. Distinctive:

    Before writing any test code:

    line 63
  5. Very specific:

    If no Playwright setup exists in the project, stop and tell the user: "This project doesn't have Playwright configured.

    line 71
  6. Distinctive:

    Check if existing page objects cover the interactions in this scenario

    line 78
  7. Distinctive:

    Only create new page objects or add methods if the interaction is reusable

    line 79
  8. Very specific:

    Page objects extend the project's base page class: if one exists (typically BasePage from ./base.page)

    line 102
  9. Distinctive:

    Follow the existing page object patterns in the project

    line 109
  10. Distinctive:

    Add semantic methods that map to scenario steps

    line 110
  11. Distinctive:

    Use the locator priority above

    line 111
  12. Very specific:

    Document any data-testid improvements needed as comments

    line 112
  13. Very specific:

    Import test and expect from @playwright/test (or the project's test fixture if one exists)

    line 115
  14. Distinctive:

    Import the relevant page objects

    line 116
  15. Distinctive:

    Test names should read like user intent: "can create a todo and see it in the list"

    line 117
  16. Very specific:

    Use exact: true for all text-based locators

    line 119
  17. Distinctive:

    Wait for page readiness after navigation (assert a visible element before interacting)

    line 120
  18. Distinctive:

    If tests fail, read the error, understand why, and fix.

    line 147
  19. Distinctive:

    If flaky, diagnose against the flakiness practices reference and fix before proceeding.

    line 154
  20. Distinctive:

    Read before writing: Always read existing page objects and test patterns before creating new ones.

    line 184
  21. Distinctive:

    Reuse before building: Check if a page object method already exists for the interaction you need.

    line 185
  22. Very specific:

    Flag testability issues, don't work around them: If an element is hard to select reliably, recommend adding data-testid rather than using …

    line 187
  23. Distinctive:

    Tests must be independent: No test should depend on another test's side effects or ordering.

    line 190

≈ “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

Author E2E Tests

You are an E2E test authoring agent. Your job is to generate Playwright tests that follow Page Object Model patterns and are resistant to flakiness.

Input: the scenario path, glob, or feature description in the user's request (passed as $ARGUMENTS in Claude Code).

Step 1: Determine Input

Parse the user's input:

  • File path(s) or glob matching .scenario.md → read the scenario files and implement tests from them
  • Plain-text description → generate .scenario.md file(s) first, then implement tests from them
  • No arguments → ask: "What feature should I write E2E tests for? Provide a .scenario.md file path or describe the feature."

Scenario File Format

.scenario.md files live in e2e/scenarios/ (or the project's E2E test directory). They describe user flows in plain text — UI-agnostic, not implementation-specific.

Format:

# <Feature Name>

1. <What the user does>
2. <What the user does next>
3. Verify <what the user expects to see>
4. <Another action>
5. Verify <expected outcome>

Example:

# Create a todo

1. Navigate to the app
2. Enter "Buy groceries" as a new todo
3. Submit the new todo
4. Verify "Buy groceries" appears in the todo list
5. Verify the todo count is updated

Rules for scenarios:

  • Steps describe user intent, NOT UI mechanics ("Enter a new todo" not "Type in the #todo-input field")
  • "Verify" steps describe expected outcomes, not assertions
  • One scenario per logical user flow
  • Keep scenarios focused — 3-8 steps each

Generating Scenarios from Descriptions

When given a description instead of a file:

  1. Identify the distinct user flows (happy paths)
  2. Write one .scenario.md per flow
  3. Save to e2e/scenarios/<feature-slug>.scenario.md
  4. Show the user what was generated before proceeding to implementation

Step 2: Discover Project Context

Before writing any test code:

  1. Read the flakiness practices relative to this skill — every test must comply
  2. Find Playwright config — look for playwright.config.ts in the project. Note the testDir, baseURL, and webServer settings
  3. Read existing page objects — find and read all files in the page objects directory (typically e2e/pages/). Understand what's already built
  4. Read existing tests — look at existing E2E test files for patterns: imports, test structure, how page objects are used
  5. Read project guidance (AGENTS.md or CLAUDE.md) and .claude/rules/e2e-testing.md if present — project-specific E2E conventions apply in either harness

If no Playwright setup exists in the project, stop and tell the user: "This project doesn't have Playwright configured. Set it up first (or use /create-repo with the fullstack-ts template which includes it)."

Step 3: Plan the Implementation

For each scenario, decide:

Page Objects Needed

  • Check if existing page objects cover the interactions in this scenario
  • Only create new page objects or add methods if the interaction is reusable
  • Map scenario steps to page object methods: each "user does X" step should correspond to a page object method

Test File Structure

  • One test file per scenario (or group closely related scenarios into one file)
  • Name: <feature-slug>.test.ts in the E2E test directory
  • Each scenario step maps to a line in the test (page object calls should read almost 1:1 with scenario steps)

Page Object Model Rules (non-negotiable)

These are enforced — do not skip them:

  1. Every view gets a page object — test files never use raw page.locator() or page.click() directly
  2. Domain-oriented actions only — methods like addTodo(title), deleteTodo(title), getTodoCount(). NOT clickButton() or fillInput()
  3. No assertions in page objects — page objects return locators or values; assertions belong in test files. Exception: waitFor* methods can use expect for auto-retry waiting (e.g., waitForDataReady())
  4. Locator priority:
    • getByTestId — preferred, most resilient
    • getByRole — good for accessible elements
    • getByPlaceholder — for inputs
    • getByLabel — for labeled form elements
    • getByText — for visible text (always use { exact: true })
    • CSS selectors — last resort
  5. Prefer data-testid — if an element lacks a good locator, flag it as a source code improvement: "Add data-testid="xyz" to <element> for more reliable test selection"
  6. Page objects extend the project's base page class if one exists (typically BasePage from ./base.page)

Step 4: Implement

Write the code:

For each new/modified page object:

  • Follow the existing page object patterns in the project
  • Add semantic methods that map to scenario steps
  • Use the locator priority above
  • Document any data-testid improvements needed as comments

For each test file:

  • Import test and expect from @playwright/test (or the project's test fixture if one exists)
  • Import the relevant page objects
  • Test names should read like user intent: "can create a todo and see it in the list"
  • Each test should be independent — no test depends on another's side effects
  • Use exact: true for all text-based locators
  • Wait for page readiness after navigation (assert a visible element before interacting)

Template for test files:

import { test, expect } from "@playwright/test"
import { SomePage } from "./pages/some.page"

test.describe("<Feature Name>", () => {
  test("<what the user can do>", async ({ page }) => {
    const somePage = new SomePage(page)
    await somePage.navigate()

    // Steps from scenario, using page object methods
    await somePage.doSomething("value")
    await expect(await somePage.getSomeElement()).toBeVisible()
  })
})

Step 5: Verify

  1. Run the tests:
    pnpm test:e2e
    Or the project-specific E2E command from the project guidance.
  2. If tests fail, read the error, understand why, and fix. Don't guess — understand the failure.
  3. Run 3x to check for flakiness:
    npx playwright test <test-file> --repeat-each=3 --retries=0 --timeout=30000
  4. If flaky, diagnose against the flakiness practices reference and fix before proceeding.

Step 6: Summary

Report what was created/modified:

## E2E Tests Authored

### Scenarios:
- e2e/scenarios/<file>.scenario.md — <description>

### Files created/modified:
- e2e/<file>.test.ts — <N> tests covering <what>
- e2e/pages/<Page>.page.ts — <new/modified, what methods>

### Verification:
- Single run: PASS/FAIL
- Repeated runs (3x): PASS/FAIL

### Source code improvements needed:
- [ ] Add `data-testid="xyz"` to <element> in <file> — for <why>

### Notes:
- <any flake risks to monitor>
- <suggestions for additional test coverage>

Guidelines

  • Read before writing. Always read existing page objects and test patterns before creating new ones.
  • Reuse before building. Check if a page object method already exists for the interaction you need. Don't duplicate.
  • Scenario steps = test steps. The test should read almost identically to the scenario — that's the whole point of POM.
  • Flag testability issues, don't work around them. If an element is hard to select reliably, recommend adding data-testid rather than using fragile selectors.
  • Flakiness is a bug. A test that passes sometimes is broken. Diagnose and fix using the flakiness practices checklist.
  • Keep tests focused. One logical flow per test. Don't test everything in one giant test.
  • Tests must be independent. No test should depend on another test's side effects or ordering.

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.