npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

playwright-page-object

v2.0.3

Published

Typed, decorator-driven Page Object Model for Playwright. Reusable, lazy locator chains in plain TypeScript classes.

Downloads

180

Readme

playwright-page-object

Typed, decorator-driven Page Object Model for Playwright. Reusable, lazy locator chains in plain TypeScript classes.

npm version CI TypeScript License: MIT

Documentation: https://sergeyshmakov.github.io/playwright-page-object/


Before / after

// Before — selectors duplicated, structure invisible
await page.getByTestId("CheckoutPage").getByTestId("PromoCodeInput").fill("SAVE20");
await page.getByTestId("CheckoutPage").getByRole("button", { name: "Apply" }).click();
// After — typed, composable, reusable
await checkoutPage.applyPromoCode("SAVE20");

What it is

A locator-composition layer, not a framework. Decorators scope a class to a Playwright locator; child decorators resolve relative to that scope. The accessor type determines output: raw Locator, a custom control, or a built-in PageObject.

  • No inheritance required for basic use
  • Lazy locator chains rebuild only when accessed
  • Three output styles coexist in the same suite
  • TypeScript-first, ECMAScript decorators (no experimentalDecorators needed)

Install

npm install -D playwright-page-object

Requirements:

  • Node >=20
  • @playwright/test >=1.35.0
  • TypeScript >=5.0 (with target: "ES2015" or higher)

Quick start

import type { Locator, Page } from "@playwright/test";
import { RootSelector, Selector, SelectorByRole } from "playwright-page-object";

@RootSelector("CheckoutPage")
class CheckoutPage {
  constructor(readonly page: Page) {}

  @Selector("PromoCodeInput")
  accessor PromoCodeInput!: Locator;

  @SelectorByRole("button", { name: "Apply" })
  accessor ApplyButton!: Locator;

  async applyPromoCode(code: string) {
    await this.PromoCodeInput.fill(code);
    await this.ApplyButton.click();
  }
}
import { test } from "@playwright/test";

test("apply promo code", async ({ page }) => {
  const checkout = new CheckoutPage(page);
  await checkout.applyPromoCode("SAVE20");
});

See the Quick Start guide for fixtures, page-only hosts, and the next steps.

Output styles

Three styles, picked per accessor. Mix freely in the same class.

Raw Locator

Minimal abstraction. Typed accessor, no helpers.

@Selector("PromoCodeInput")
accessor PromoCodeInput!: Locator;

Plain Classes guide →

Custom controls

Pass any class whose constructor accepts a Locator. Reuse your existing control library.

@Selector("PromoCodeInput", InputControl)
accessor PromoCode!: InputControl;

Custom Controls guide →

Built-in POM

PageObject / ListPageObject for wait helpers, soft assertions, and filter chains.

class CheckoutPage extends RootPageObject {
  @Selector("PromoCodeInput")
  accessor PromoCode = new PageObject();

  async applyPromo(code: string) {
    await this.PromoCode.waitVisible();
    await this.PromoCode.$.fill(code);
  }
}

Built-In POM guide →

Context resolution

Child decorators resolve in this order: a @RootSelector-managed locator, then a locator property on the host, then page.locator("body") if page is present. The first match wins.

Context Resolution reference →

Documentation

The full documentation site covers every guide, the API reference, and the v1 → v2 migration:

https://sergeyshmakov.github.io/playwright-page-object/

  • Getting Started — install, quick start, choosing a style
  • Guides — plain classes, fragments, custom controls, built-in POM, lists, fixtures, incremental adoption
  • Reference — context resolution, migration v1 → v2, troubleshooting
  • API — decorators, PageObject, RootPageObject, ListPageObject, createFixtures

AI tooling

This package ships an Agent Skills-compatible skill so AI assistants load library-specific guidance on demand:

npx ctx7 skills install /sergeyshmakov/playwright-page-object playwright-page-object

It is also indexed in Context7 and documented in a Cubic wiki. See AI Tooling in the docs.

Migrating from v1

See the migration guide. Most changes are mechanical renames.

Contributing

See CONTRIBUTING.md.

License

MIT License