Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Agent Skills guide

Skill recipe: your test suite conventions

A worked skill that teaches agents your Playwright locator policy, fixtures and assertion rules, so generated tests match your team's and stay stable.

By Intermediate · Updated 25 November 20266 min read
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark
On this page

A test conventions skill puts your Playwright rules in front of the agent every time it writes or fixes a test: the locator order you allow, the fixtures to reuse instead of logging in again, the assertions you prefer and the waits you ban. Generated tests then look like your team wrote them.

Ask an agent to write a Playwright test and you get something that passes today: CSS selectors copied from the DOM, a waitForTimeout(2000) to be safe, a fresh login in every test. It works until someone renames a class. Your suite almost certainly has rules that prevent this: a locator policy, shared fixtures, assertion habits. A skill puts those rules in front of the agent every time it writes or fixes a test. This recipe builds one for a Playwright suite in TypeScript. We re-ran it on 25 November 2026 with Playwright 1.64.1: the SKILL.md passes the spec’s skills-ref validator, and the “with the skill” test below passed five runs out of five (--repeat-each=5) against a stub page whose save button updates the heading after a delay.

What goes in

  1. Locator policy: which locators to use, in order, and which are banned.
  2. Fixtures and helpers: what exists so the agent stops reinventing login and test data.
  3. Assertion rules: web-first assertions, what to check and what never to check.
  4. Structure: file names, tags, where page objects live.
  5. Flakiness rules: what to do instead of sleeping or retrying.

SKILL.md

---
name: acme-e2e-conventions
description: >-
  Acme conventions for writing, fixing and reviewing Playwright end-to-end
  tests in e2e/: locator policy, fixtures, assertions and anti-flake rules.
  Use when creating or editing any *.spec.ts under e2e/, when a Playwright
  test is flaky, or when reviewing test code. Not for unit tests in src/.
---

# Acme end-to-end test conventions

## Locators, in this order

1. `getByRole` with an accessible name.
2. `getByLabel` for form fields.
3. `getByTestId` only when 1 and 2 are impossible. Test IDs use kebab-case
   and must be added to the component, not guessed.
Never use CSS classes, XPath, `nth()` or text that includes prices or dates.

## Fixtures

Import `test` and `expect` from `e2e/fixtures`, never from `@playwright/test`.
Available fixtures (see references/fixtures.md):
- `loggedInPage`: a page with a signed-in standard user. Do not log in by hand.
- `adminPage`: same for an admin.
- `seed`: creates test data through the API, cleaned up after the test.

## Assertions

- Use web-first assertions: `await expect(locator).toBeVisible()`, never
  `expect(await locator.isVisible()).toBe(true)`.
- Assert what the user sees or the outcome of the action, not implementation
  details such as CSS or request counts.
- No snapshot tests of whole pages.

## Flakiness

- Never use `waitForTimeout`. Wait for a locator, a URL or a response.
- Do not add retries (`retries` in the config or in
  `test.describe.configure`) or raise timeouts to make a test pass. Find
  the race and fix it, or report it.

## Structure

- One feature per file: `e2e/<area>/<feature>.spec.ts`.
- Tag tests that need payment sandbox with `@payments`.

## Before you finish

Run `pnpm exec playwright test <file> --repeat-each=5` and report the result.

The --repeat-each=5 step is the cheapest flakiness check there is: a test that passes once and fails once in five is not done.

references/fixtures.md

List each fixture with its signature and a two-line example. If fixtures live in e2e/fixtures/index.ts, you could tell the agent to read that file instead; a short reference is still worth it because it explains intent (“seed uses the API, not the UI, so it is fast and safe to use in every test”). For example:

# Fixtures (e2e/fixtures/index.ts)

## loggedInPage: Page
A page signed in as a standard user, with storage state reused from
global setup, so it costs no login time.
  test("...", async ({ loggedInPage: page }) => { await page.goto("/"); });

## adminPage: Page
Same, signed in as an admin. Use only for admin-only screens.

## seed
Creates data through the API and deletes it after the test.
  const project = await seed.project({ name: "Q4 plan" });
  const user = await seed.user({ role: "viewer" });
Use it for every piece of data a test reads. Never rely on data
another test created, or on anything already in the database.

The “why” lines matter more than the signatures. An agent that knows the login fixture reuses storage state stops writing its own login steps “to be safe”.

Example of the difference

Without the skill, a typical agent-written test:

test("user can rename project", async ({ page }) => {
  await page.goto("/login");
  await page.fill("#email", "test@example.com");
  await page.fill("#password", "password");
  await page.click("button.btn-primary");
  await page.waitForTimeout(2000);
  await page.click(".project-card:nth-child(1) .menu");
  await page.click("text=Rename");
  await page.fill("input.rename", "Renamed");
  await page.keyboard.press("Enter");
  expect(await page.locator(".project-card h3").first().textContent()).toBe("Renamed");
});

With it:

import { test, expect } from "../fixtures";

test("user can rename a project", async ({ loggedInPage: page, seed }) => {
  const project = await seed.project({ name: "Q4 plan" });
  await page.goto(`/projects/${project.id}`);

  await page.getByRole("button", { name: "Project actions" }).click();
  await page.getByRole("menuitem", { name: "Rename" }).click();
  await page.getByLabel("Project name").fill("Q4 plan (final)");
  await page.getByRole("button", { name: "Save" }).click();

  await expect(page.getByRole("heading", { name: "Q4 plan (final)" })).toBeVisible();
});

The second test creates its own data, uses the shared login, survives a CSS refactor and has no sleeps. The fixture names here are this recipe’s; use yours.

Testing it

Start each test in a fresh session and do not name the skill. These should load it:

Add an end-to-end test that an admin can invite a user from the
team settings page and the invite appears in the pending list.
e2e/billing/checkout.spec.ts fails about one run in ten on CI with a
timeout on the "Pay now" button. Find out why and fix it.
Review this Playwright test before I merge it:
await page.click(".btn-primary"); await page.waitForTimeout(3000);

Check each answer against the rules: test and expect imported from the fixtures file, role or label locators, no waitForTimeout, no new retries, and the --repeat-each=5 result reported at the end. For the flaky test, the right answer names the race (usually an assertion that runs before a response arrives) instead of raising a timeout. For the review, the agent should flag both lines and say which rule each breaks.

These should not load it:

Write a Vitest unit test for the formatPrice helper in src/utils/money.ts.
Why is the build failing on the TypeScript step?

If the skill loads for the unit test, tighten “Not for unit tests in src/” in the description or add the folder name to it. If it does not load for the flaky-test prompt even though the description says “flaky”, add the words your team actually uses (“intermittent”, “fails on CI”, “timeout”). Descriptions match on the request’s wording, not on what the skill is about.

Pairs well with

If skills are new to you, start with what Agent Skills are. This one is a checklist with one reference file, two of the shapes in Agent Skill design patterns. To check it changes the output rather than just loading, run it against a baseline as described in testing and evaluating Agent Skills, and keep it in the repository under .agents/skills/ or .claude/skills/ as how to install Agent Skills explains for each agent.

  • Generate Playwright tests with AI agents, then review them

    Approve a test plan before any code exists, generate tests from it and review them like production code.

    WorkflowIntermediate1 h 30 min7 steps

  • Playwright test agents: planner, generator and healer

    How Playwright's planner, generator and healer test agents work, how to set them up with Claude Code or VS Code, and how to review the tests they write for you.

    TutorialIntermediate45 min

  • AI for test engineers

    An AI course for testers: apply generative AI to everyday test automation, from AI-assisted test design to generating, healing and reviewing Playwright tests.

    Learning pathBeginner9 h10 steps

  • Playwright

    End-to-end testing framework for web apps, with built-in test agents.

    Tool

Back to top