AGENT SKILL

pw-locator-fixer

Scans a Playwright spec or Page Object for brittle locators and rewrites them to resilient ones. Use when an SDET says "fix these locators", "my selectors are flaky", "replace XPath with getByRole", "make these locators resilient", or pastes code full of nth-child/CSS-class/text selectors. Produces a before/ after rewrite map plus patched code — the engineer verifies each swap.

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

01 前言 Front Matter

name
pw-locator-fixer
license
MIT
metadata
{ "pack": "playwright", "author": "TheTestingAcademy", "version": "1.0.0" }
description
Scans a Playwright spec or Page Object for brittle locators and rewrites them to resilient ones. Use when an SDET says "fix these locators", "my selectors are flaky", "replace XPath with getByRole", "make these locators resilient", or pastes code full of nth-child/CSS-class/text selectors. Produces a before/ after rewrite map plus patched code — the engineer verifies each swap.

03 SKILL.md 正文

PW Locator Fixer

You audit locators and propose resilient replacements the engineer must verify against the live DOM — a swap that reads well can still target the wrong node.

When to use

  • A spec/POM uses XPath, nth-child, CSS-class, or raw-text selectors.
  • Tests fail intermittently on element lookups.
  • Someone says "fix/harden/de-flake these locators".

Workflow

  1. Scan the provided code and flag every brittle locator:
    • XPath (//div[...]), page.locator('.some-class'), :nth-child, deep CSS descendant chains, index-based .nth(3), and unanchored text matches.
  2. Rank the fix per element using the resilience ladder: getByRole (name) → getByLabel → getByPlaceholder → getByText (exact) → getByTestId. Reach for getByTestId when semantics are weak, not as the first choice.
  3. Rewrite each locator, preserving intent. Where the original relied on position/text that maps to no stable attribute, mark // TODO: needs data-testid rather than inventing one.
  4. Emit a rewrite map (before → after → why) so the change is reviewable.
  5. Note residual risk — any swap you couldn't confirm without the real DOM.

Output shape

Rewrite map
  ✗ page.locator('//button[2]')          → ✓ getByRole('button', { name: 'Save' })
  ✗ page.locator('.err-msg')             → ✓ getByTestId('form-error')   // needs data-testid
  ✗ page.locator('tr:nth-child(3) td')   → ✓ getByRole('row', { name: /Order 1042/ })
// before
await page.locator('.login-form input.username').fill('ada');
// after
await page.getByLabel('Username').fill('ada');

Guardrails

  • These are proposed swaps the engineer must run and confirm — never assume the new locator resolves to the same element without checking the real DOM.
  • Never invent a data-testid or accessible name; if none exists, flag that the app needs one (// TODO: needs data-testid).
  • Prefer role/label semantics over testid; testid is the fallback, not the default.
  • Do not silently change behavior (strictness, count) — call out multi-match risks.

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-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.

★ 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