Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

docs(java): add waitForCondition method (#21768)

Yury Semikhatskya61b5449328a
diff --git a/docs/src/api/class-browsercontext.md b/docs/src/api/class-browsercontext.md
index 54719363e8..f3bef29d01 100644
--- a/docs/src/api/class-browsercontext.md
+++ b/docs/src/api/class-browsercontext.md
@@ -1324,6 +1324,38 @@ Optional handler function used to register a routing with [`method: BrowserConte
Optional handler function used to register a routing with [`method: BrowserContext.route`].
+## async method: BrowserContext.waitForCondition
+* since: v1.32
+* langs: java
+
+The method will block until the condition returns true. All Playwright events will
+be dispatched while the method is waiting for the condition.
+
+**Usage**
+
+Use the method to wait for a condition that depends on page events:
+
+```java
+List<String> failedUrls = new ArrayList<>();
+context.onResponse(response -> {
+ if (!response.ok()) {
+ failedUrls.add(response.url());
+ }
+});
+page1.getByText("Create user").click();
+page2.getByText("Submit button").click();
+context.waitForCondition(() -> failedUrls.size() > 3);
+```
+
+### param: BrowserContext.waitForCondition.condition
+* since: v1.32
+- `condition` <[BooleanSupplier]>
+
+Condition to wait for.
+
+### option: BrowserContext.waitForCondition.timeout = %%-wait-for-function-timeout-%%
+* since: v1.32
+
## async method: BrowserContext.waitForEvent
* since: v1.8
* langs: js, python
diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md
index 5e44e58a29..ef304b556f 100644
--- a/docs/src/api/class-page.md
+++ b/docs/src/api/class-page.md
@@ -4784,6 +4784,33 @@ class FrameExamples
### option: Page.waitForSelector.timeout = %%-input-timeout-js-%%
* since: v1.8
+## async method: Page.waitForCondition
+* since: v1.32
+* langs: java
+
+The method will block until the codition returns true. All Playwright events will
+be dispatched while the method is waiting for the codition.
+
+**Usage**
+
+Use the method to wait for a condition that depends on page events:
+
+```java
+List<String> messages = new ArrayList<>();
+page.onConsoleMessage(m -> messages.add(m.text()));
+page.getByText("Submit button").click();
+page.waitForCondition(() -> messages.size() > 3);
+```
+
+### param: Page.waitForCondition.condition
+* since: v1.32
+- `condition` <[BooleanSupplier]>
+
+Codition to wait for.
+
+### option: Page.waitForCondition.timeout = %%-wait-for-function-timeout-%%
+* since: v1.32
+
## async method: Page.waitForTimeout
* since: v1.8