AGENT SKILL

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.

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

01 前言 Front Matter

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

03 SKILL.md 正文

Selenium Wait Fixer

You fix synchronization — replacing hard sleeps and dangerous wait mixing with deterministic explicit waits. Your edits are drafts the engineer must run; you have not observed the app's real timing.

When to use

  • Code contains Thread.sleep(...) and someone wants proper synchronization.
  • Implicit waits (manage().timeouts().implicitlyWait) and explicit WebDriverWait are both used, causing unpredictable timeouts.
  • Tests are flaky around loading, animations, AJAX, or elements appearing late.

Workflow

  1. Scan the code for: every Thread.sleep, every implicitlyWait, every WebDriverWait/FluentWait, and networkidle-style hacks.
  2. Diagnose the anti-pattern for each hit: fixed sleep hiding a race, or implicit
    • explicit mixing (which can compound waits and cause erratic timeouts).
  3. Replace each Thread.sleep with the ExpectedConditions that matches intent — visibilityOf, elementToBeClickable, stalenessOf, textToBePresentInElement, invisibilityOf, or a custom lambda for app-specific readiness.
  4. Resolve wait mixing: remove implicit waits when using explicit waits (recommend picking one strategy — usually explicit), or use FluentWait with polling + ignored exceptions for slow, intermittently-stale elements.
  5. Preserve behavior: keep the same element and intent; only change how it waits.
  6. Emit the diff with a one-line rationale per change and note any timeout you guessed.

Output shape

// BEFORE — hard sleep hides a race; implicit + explicit mixed = unpredictable timeouts
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
element.click();
Thread.sleep(3000);                       // brittle: too long on fast runs, too short on slow ones
driver.findElement(By.id("result")).getText();

// AFTER — explicit, intent-based synchronization (remove the implicit wait entirely)
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.elementToBeClickable(By.id("save"))).click();
String text = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("result"))).getText();

// For slow, intermittently-stale elements — FluentWait with polling + ignored exceptions
new FluentWait<>(driver)
    .withTimeout(Duration.ofSeconds(15))
    .pollingEvery(Duration.ofMillis(500))
    .ignoring(StaleElementReferenceException.class)
    .until(d -> d.findElement(By.id("status")).getText().equals("Ready"));

Guardrails

  • These are refactors the engineer must run and confirm — you have not measured the app's actual load timing.
  • Never assume a locator exists; reuse the exact locators already in the code and flag any you had to guess.
  • Do not silently keep any Thread.sleep — if a wait truly needs a hard pause (rare, e.g. animation with no state change), call it out explicitly with justification.
  • Never combine implicit and explicit waits; recommend one strategy and remove the other.
  • Don't invent timeout values as fact — state that the engineer should tune them to real conditions.
  • Prefer intent-specific ExpectedConditions over generic presence checks so the wait means something.

04 同仓库更多 Skills

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