AGENT SKILL

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.

License 许可
MIT
最近更新
2026-07-15
Stars
★ 4
Forks
8

01 前言 Front Matter

name
se-page-object-builder
license
MIT
metadata
{ "pack": "selenium", "author": "TheTestingAcademy", "version": "1.0.0" }
description
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.

03 SKILL.md 正文

Selenium Page Object Builder

You draft a Page Object the engineer still has to wire up and run — a reusable class that encapsulates one page's locators and actions. Locators are proposals until confirmed against the real DOM.

When to use

  • A page's fields/buttons/flows are described and someone wants a POM class.
  • Someone says "make a page object" / "encapsulate these locators" / "give me the POM for X page".
  • Inline driver.findElement calls in a test need refactoring into a page class.

Workflow

  1. Identify the page's responsibilities: the elements it owns and the user actions it exposes (e.g. login(), search(), getErrorText()).
  2. Choose a style — PageFactory @FindBy for simple pages, or explicit By locators for dynamic/lazy elements (explicit is more robust against staleness).
  3. Assign stable locators — By.id > By.cssSelector > relative locators; avoid absolute XPath. Flag any locator you cannot confirm with a // TODO comment.
  4. Add a WebDriverWait field; action methods wait for element readiness before acting. Never use Thread.sleep.
  5. Return types: navigation actions return the next page object; queries return data (String/boolean). Keep methods small and intention-revealing.
  6. Emit the class with a constructor taking WebDriver, then list unconfirmed locators.

Output shape

public class LoginPage {
    private final WebDriver driver;
    private final WebDriverWait wait;

    private final By username = By.id("username");
    private final By password = By.id("password");                 // TODO: confirm locator
    private final By submit   = By.cssSelector("button[type='submit']");

    public LoginPage(WebDriver driver) {
        this.driver = driver;
        this.wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    }

    public DashboardPage loginAs(String user, String pass) {
        wait.until(ExpectedConditions.visibilityOfElementLocated(username)).sendKeys(user);
        driver.findElement(password).sendKeys(pass);
        driver.findElement(submit).click();
        return new DashboardPage(driver);
    }

    public boolean isErrorShown() {
        return !driver.findElements(By.cssSelector("[data-test='error']")).isEmpty();
    }
}

Guardrails

  • This is a draft the engineer must review and run — the class is unverified until exercised against the app.
  • Never assume a locator exists; every unverified locator is a // TODO: confirm locator and appears in your notes.
  • Keep pages focused — one class per page/component; don't cram unrelated flows in.
  • No assertions inside the page object; assertions belong in tests.
  • Never use Thread.sleep; synchronize with WebDriverWait/ExpectedConditions.
  • Prefer explicit By locators when elements are dynamic — PageFactory proxies can go stale.
  • Do not fabricate fields the page doesn't have; a missing element is a question.

04 同仓库更多 Skills

PramodDutta
PramodDutta/skillmasterclass

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.

★ 4
PramodDutta
PramodDutta/skillmasterclass

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.

★ 4
PramodDutta
PramodDutta/skillmasterclass

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.

★ 4
PramodDutta
PramodDutta/skillmasterclass

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.

★ 4
PramodDutta
PramodDutta/skillmasterclass

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.

★ 4
PramodDutta
PramodDutta/skillmasterclass

se-framework-scaffolder

Scaffolds a Maven Selenium framework — TestNG suite, base test, Page Object package, config loader, logging, and reporting hooks. Use when an SDET says "scaffold a Selenium framework", "set up a new Maven Selenium project", "give me a POM/TestNG project structure", or is starting automation from zero. Produces a starter layout and files the engineer must build, run, and adapt.

★ 4