agentleFS
sayurionishisayurionishi/playwright-scaffold/.claude/skills/page-objects/SKILL.md

page-objects

Skill1 starsChanged 3 months agoMITView on GitHub

Use when creating a page object for a new screen, adding locators/actions to an existing one, or extracting a reusable component object. Defines the POM conventions.

1 other project uses 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, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

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

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

    Locators-on-top: Every locator is a class field.

    line 38
  2. Very specific:

    After creating a page object, register it in fixtures/pom/page-object-fixture.ts.

    line 52

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

Page Objects

The contract: page objects perform actions and expose locators; specs assert. Tests read like user stories; the DOM lives behind the page object.

Anatomy

export class ProductsPage extends BasePage {
  // ── Locators on top (single source of truth) ──
  readonly heading = this.page.getByRole('heading', { name: 'Products' }); // public: specs assert on it
  private readonly addButton = this.page.getByRole('button', { name: 'Add product' });
  private readonly nameInput = this.page.getByLabel('Name');

  async goto(): Promise<void> {
    await this.page.goto(Routes.PRODUCTS);
  }

  // ── Actions only — no expect() here ──
  async addProduct(name: string): Promise<void> {
    await this.addButton.click();
    await fillAndBlur(this.nameInput, name);
    const saved = waitForRest(this.page, ApiEndpoints.PRODUCTS); // pre-register
    await this.page.getByRole('button', { name: 'Save' }).click();
    await saved;
  }
}

Rules

  1. Extends BasePage. Constructor takes page; page is protected — specs use the page fixture for URL asserts, not somePage.page.
  2. Locators-on-top. Every locator is a class field. readonly (public) if a spec asserts on it; private readonly if internal-only. Never declare locators inline in methods.
  3. No assertions. No expect, no isVisibleReturningBoolean() wrappers. Expose the locator; let the spec assert. (await expect(page.heading).toBeVisible() lives in the spec.)
  4. Waits are fine (they're not assertions): locator.waitFor({ state }), the network.ts helpers.
  5. Deterministic waits inside actions — pre-register response waits; never waitForTimeout/networkidle.
  6. Include feedback locators — success/error/validation elements, so specs can assert outcomes.

Components — extract on the 3rd occurrence

A reusable UI pattern (search box, modal, tab bar) becomes a pages/components/*.component.ts only when it appears in 3+ page objects. Before that, keep it as page-object methods. A component takes its scope (Page | Locator) so it works inside modals/panels. See pages/components/search.component.ts.

Register + consume via fixture

After creating a page object, register it in fixtures/pom/page-object-fixture.ts. Tests receive it by destructuring (async ({ productsPage }) => …) — never new ProductsPage(page) in a test.

Phases

  1. ls pages/ — resolve area, avoid duplicates.
  2. Explore the live screen (playwright-cli). 3. Propose locators + actions + feedback elements.
  3. Build (rules above). 5. Register in the POM fixture. 6. Use via fixture in the spec.

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.