diff --git a/docs-site/docs/guides/base-page.md b/docs-site/docs/guides/base-page.md index 7f52ad4..a31ac6f 100644 --- a/docs-site/docs/guides/base-page.md +++ b/docs-site/docs/guides/base-page.md @@ -82,7 +82,7 @@ if (isDisplayed(By.id("error-banner"))) { ## Using WaitEngine directly -For advanced waits not covered by the helpers above, use `getWait()`: +For advanced waits not covered by the helpers above, call `WaitEngine`'s static methods directly: ```java import com.seleniumboot.wait.WaitEngine; @@ -94,7 +94,7 @@ public class DashboardPage extends BasePage { } public boolean isLoaded() { - getWait().waitForInvisible(By.cssSelector(".spinner")); + WaitEngine.waitForInvisible(By.cssSelector(".spinner")); return isDisplayed(By.id("dashboard-content")); } } @@ -119,7 +119,7 @@ public class CheckoutPage extends BasePage { public void pay() { click(PAY_BTN); - getWait().waitForVisible(SUCCESS); + WaitEngine.waitForVisible(SUCCESS); } public String getConfirmationMessage() { diff --git a/docs-site/docs/guides/wait-engine.md b/docs-site/docs/guides/wait-engine.md index 13ce39e..8b1a7d9 100644 --- a/docs-site/docs/guides/wait-engine.md +++ b/docs-site/docs/guides/wait-engine.md @@ -8,7 +8,11 @@ sidebar_position: 3 # WaitEngine -`WaitEngine` provides fluent explicit waits. It is pre-configured with the timeout from `selenium-boot.yml` (`timeouts.explicit`) and is available in every `BasePage` via `getWait()`. +`WaitEngine` provides explicit waits as static methods, pre-configured with the timeout from `selenium-boot.yml` (`timeouts.explicit`). Call them directly — `WaitEngine.waitForVisible(...)` — from anywhere in a `BasePage` or `BaseTest`. + +```java +import com.seleniumboot.wait.WaitEngine; +``` --- @@ -17,72 +21,83 @@ sidebar_position: 3 ### Element visibility ```java -getWait().waitForVisible(By.id("modal")); -getWait().waitForInvisible(By.cssSelector(".spinner")); // wait for loaders to disappear +WaitEngine.waitForVisible(By.id("modal")); +WaitEngine.waitForInvisible(By.cssSelector(".spinner")); // wait for loaders to disappear ``` ### Clickability ```java -getWait().waitForClickable(By.id("submit")); +WaitEngine.waitForClickable(By.id("submit")); ``` ### Text content ```java -getWait().waitForText(By.cssSelector("h1"), "Welcome back"); +WaitEngine.waitForText(By.cssSelector("h1"), "Welcome back"); ``` ### Attribute value ```java -getWait().waitForAttributeContains(By.id("status"), "class", "active"); // substring -getWait().waitForAttribute(By.id("status"), "aria-expanded", "true"); // exact match +WaitEngine.waitForAttributeContains(By.id("status"), "class", "active"); // substring +WaitEngine.waitForAttribute(By.id("status"), "aria-expanded", "true"); // exact match ``` ### Text matches (regex) ```java // Wait until the element's visible text matches a regular expression -getWait().waitForTextMatches(By.cssSelector(".total"), "\\$\\d+\\.\\d{2}"); +WaitEngine.waitForTextMatches(By.cssSelector(".total"), "\\$\\d+\\.\\d{2}"); ``` ### URL matches (regex) ```java -getWait().waitForUrlContains("/orders"); // substring -getWait().waitForUrlMatches(".*/orders/\\d+"); // regular expression +WaitEngine.waitForUrlContains("/orders"); // substring +WaitEngine.waitForUrlMatches(".*/orders/\\d+"); // regular expression ``` ### DOM staleness ```java WebElement old = driver.findElement(By.id("row-1")); -getWait().waitForStaleness(old); // wait for DOM replacement / AJAX reload +WaitEngine.waitForStaleness(old); // wait for DOM replacement / AJAX reload ``` ### Page load ```java -getWait().waitForPageLoad(); // waits until document.readyState === "complete" +WaitEngine.waitForPageLoad(); // waits until document.readyState === "complete" ``` +### Network + +Waits driven by the browser's network activity — CDP on Chrome/Edge, [BiDi](https://www.w3.org/TR/webdriver-bidi/) on Firefox and other BiDi-capable browsers. Throws `UnsupportedOperationException` on drivers with neither. + +```java +// Wait until no request has been in flight for 500ms (the default), or a custom quiet period +WaitEngine.waitForNetworkIdle(); +WaitEngine.waitForNetworkIdle(Duration.ofSeconds(1)); + +// Wait for a response matching a URL glob (same syntax as NetworkMock.stub), get its status code +int status = WaitEngine.waitForResponse("**/api/checkout"); +``` + +Both are bounded by the configured explicit timeout by default; pass a `Duration` to override it for `waitForResponse`. + ### Custom condition ```java // Escape hatch — pass any ExpectedCondition -getWait().wait(ExpectedConditions.numberOfWindowsToBe(2)); +WaitEngine.wait(ExpectedConditions.numberOfWindowsToBe(2)); ``` --- ## Timeout override -Use a custom timeout for a single wait without changing the global config: - -```java -getWait(30).waitForVisible(By.id("slow-element")); // 30-second timeout -``` +`waitForNetworkIdle(Duration)` and `waitForResponse(String, Duration)` take an explicit timeout per call. Every other method reads `timeouts.explicit` from `selenium-boot.yml`. --- @@ -103,7 +118,7 @@ timeouts: Thread.sleep(3000); // ✅ do this instead -getWait().waitForVisible(By.id("result")); +WaitEngine.waitForVisible(By.id("result")); ``` ```java @@ -111,6 +126,6 @@ getWait().waitForVisible(By.id("result")); new WebDriverWait(driver, Duration.ofSeconds(10)) .until(ExpectedConditions.visibilityOf(...)); -// ✅ use getWait() — reads timeout from config -getWait().waitForVisible(By.id("result")); +// ✅ WaitEngine reads the timeout from config +WaitEngine.waitForVisible(By.id("result")); ``` diff --git a/docs-site/docs/migration/from-selenium-testng.md b/docs-site/docs/migration/from-selenium-testng.md index d1db95e..4b676b4 100644 --- a/docs-site/docs/migration/from-selenium-testng.md +++ b/docs-site/docs/migration/from-selenium-testng.md @@ -119,8 +119,8 @@ WaitUtils.waitVisible(driver, By.id("login")).click(); ```java $("#login").click(); // auto-waits for clickable -getWait().waitForInvisible(By.cssSelector(".spinner")); -getWait().waitForText(By.cssSelector("h1"), "Welcome back"); +WaitEngine.waitForInvisible(By.cssSelector(".spinner")); +WaitEngine.waitForText(By.cssSelector("h1"), "Welcome back"); ``` No `Thread.sleep()`, no per-page `WebDriverWait` construction, no passing `driver` around. See the [WaitEngine guide](/docs/guides/wait-engine).