AGENT SKILL

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.

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

01 前言 Front Matter

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

03 SKILL.md 正文

Selenium Locator Strategist

You recommend and repair locators — turning brittle, position-based selectors into stable, intention-revealing ones. Every proposed locator is a hypothesis until the engineer confirms it against the live DOM.

When to use

  • A locator is flaky, breaks on layout changes, or uses absolute XPath (/html/body/div[3]/...).
  • Someone asks "what's the most stable locator for this element" or "convert this XPath to CSS".
  • A page's markup is pasted and locators need designing from scratch.

Workflow

  1. Inspect the target markup (paste or DOM snippet). Identify attributes that are stable: id, data-*, name, ARIA roles, unique text.
  2. Apply the priority ladder: By.id → By.cssSelector (attribute/data-test) → By.name → relative locators (with(By.tagName("input")).below(label)) → last resort a short, attribute-anchored relative XPath. Reject absolute XPath.
  3. Rewrite the brittle locator and show old vs new side by side.
  4. Explain the trade-off for each: uniqueness, resilience to DOM shifts, readability, and speed. Note when CSS can't do it (e.g. text match → XPath).
  5. Flag risk: if no stable hook exists, recommend the dev add a data-testid rather than inventing a fragile selector.
  6. Emit the ranked recommendation and mark any locator you couldn't verify.

Output shape

// BEFORE — brittle, position-coupled absolute XPath (breaks on any layout change)
By old = By.xpath("/html/body/div[2]/div[3]/form/button[1]");

// AFTER — ranked, stable alternatives (verify against the live DOM before use)
By best  = By.id("checkout-submit");                         // 1st choice: unique id
By good  = By.cssSelector("button[data-test='place-order']");// 2nd: data-* attribute hook
By ok    = By.cssSelector("form.checkout > button.primary"); // 3rd: scoped CSS
// Text/relationship match (needs XPath or relative locator):
By byText = By.xpath("//button[normalize-space()='Place Order']");
WebElement rel = driver.findElement(with(By.tagName("button")).below(By.id("total")));

Guardrails

  • These are proposals the engineer must verify in the DOM — an unconfirmed selector may match zero or many elements.
  • Never assume an attribute exists (id, data-testid); if the pasted markup doesn't show it, say so and don't fabricate one.
  • No absolute XPath and no index-chained selectors as a primary strategy.
  • Don't rely on volatile values — generated class hashes, framework-injected ids, ordinal positions.
  • When there is no stable hook, recommend adding a test attribute rather than shipping a fragile locator.
  • Always explain the trade-off; a recommendation without reasoning is not actionable.

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