pw-page-object-builder
Builds a Playwright Page Object Model class from a page or URL. Use when an SDET says "make a page object for the login page", "build a POM for the dashboard", "extract locators into a page class", or wants to refactor inline selectors into a reusable class. Produces locators-as-methods (getByTestId/ getByRole), action methods, and a static PATH — a draft to review.
- License 许可
- MIT
- 最近更新
- 2026-07-15
- Stars
- ★ 4
- Forks
- 8
01 前言 Front Matter
- name
- pw-page-object-builder
- license
- MIT
- metadata
- { "pack": "playwright", "author": "TheTestingAcademy", "version": "1.0.0" }
- description
- Builds a Playwright Page Object Model class from a page or URL. Use when an SDET says "make a page object for the login page", "build a POM for the dashboard", "extract locators into a page class", or wants to refactor inline selectors into a reusable class. Produces locators-as-methods (getByTestId/ getByRole), action methods, and a static PATH — a draft to review.
03 SKILL.md 正文
PW Page Object Builder
You draft a Page Object class the engineer must wire up and verify — never a finished, guaranteed-correct class. You encode resilient locators and clear actions.
When to use
- A page/URL/screenshot is described and needs a reusable POM.
- Inline locators in a spec should be extracted into a class.
- Someone says "build/make a page object for X".
Workflow
- Identify the page's role and its stable entry path →
static readonly PATH. - Inventory the elements the tests interact with. Group into logical clusters (header, form, table). If it exceeds ~50 locators, split into sub-page classes and say so — one bloated POM is a smell.
- Express each locator as a method returning a
Locator, preferringgetByRole/getByLabel/getByTestId. Never store a resolved element; return the locator lazily so it re-queries. - Add action methods that orchestrate locators (e.g.
login(user, pass)), with explicit return types. Keep assertions out of the POM; expose state. - Flag guessed selectors with
// TODO: confirmand list them for review.
Output shape
import { type Page, type Locator } from '@playwright/test';
export class LoginPage {
static readonly PATH = '/login';
constructor(private readonly page: Page) {}
usernameInput = (): Locator => this.page.getByLabel('Username');
passwordInput = (): Locator => this.page.getByLabel('Password');
submitButton = (): Locator => this.page.getByRole('button', { name: 'Sign in' });
errorBanner = (): Locator => this.page.getByTestId('login-error');
async goto(): Promise<void> {
await this.page.goto(LoginPage.PATH);
}
async login(username: string, password: string): Promise<void> {
await this.usernameInput().fill(username);
await this.passwordInput().fill(password);
await this.submitButton().click();
}
}
Guardrails
- This is a draft the engineer must run and review — never assume a selector,
testid, or PATH exists; mark guesses with
// TODO: confirm. - Never fabricate accessible names or data-testids you weren't shown.
- Locators return
Locator(lazy) — never cache resolved elements orElementHandle. - No XPath /
nth-child/ CSS-class selectors. No assertions inside the POM. - Cap at ~50 locators per class; split into sub-pages when larger.
04 同仓库更多 Skills
se-wait-fixer
Scans Selenium Java code for Thread.sleep and for implicit+explicit wait mixing, then replaces them with WebDriverWait/ExpectedConditions or FluentWait to fix synchronization. Use when an SDET says "remove Thread.sleep from my tests", "fix the flaky waits", "my implicit and explicit waits conflict", or pastes code full of hard sleeps. Produces refactors the engineer must run and confirm.
se-test-generator
Generates a runnable Selenium 4 + TestNG test in Java from a plain-language scenario, using explicit waits and stable locators. Use when an SDET says "write a Selenium test for login", "generate a TestNG test for the checkout flow", "automate this scenario in Selenium", or pastes Gherkin/steps and wants Java WebDriver code. Produces a draft test the engineer must review and run.
se-report-integrator
Integrates reporting (Allure or ExtentReports) into a Selenium + TestNG suite with listeners, screenshot-on-failure, and step logging. Use when an SDET says "add Allure to my tests", "set up ExtentReports", "capture a screenshot on failure", "add a TestNG listener for reporting", or wants readable run reports. Produces listener and config code the engineer must run to generate a report.
se-page-object-builder
Builds a Page Object Model class in Java (PageFactory @FindBy or explicit locators) with action methods and a WebDriverWait for a given page. Use when an SDET says "create a page object for the login page", "build a POM class", "refactor these locators into a page object", or pastes a page's fields and wants a reusable POM. Produces a draft class the engineer must review and run.
se-locator-strategist
Recommends and repairs Selenium locator strategy — replaces brittle absolute XPath with By.id, By.cssSelector, or Selenium 4 relative locators, and explains the trade-offs. Use when an SDET says "this XPath keeps breaking", "make this locator more stable", "why is my locator flaky", "convert this XPath to CSS", or pastes selectors to harden. Produces proposals the engineer must verify in the DOM.
se-grid-configurator
Configures Selenium Grid 4 (hub-and-node or standalone, including Docker) and wires RemoteWebDriver for parallel and distributed runs. Use when an SDET says "set up Selenium Grid", "run my tests on a remote grid", "dockerize Selenium Grid 4", "point my tests at RemoteWebDriver", or wants parallel execution across nodes. Produces config and code the engineer must run and validate in their environment.