From a61b5449328ad23f8743b4d35c643ff8d4bdbc1c Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 17 Mar 2023 13:02:59 -0700 Subject: [PATCH] docs(java): add waitForCondition method (#21768) https://github.com/microsoft/playwright-java/issues/1228 --- docs/src/api/class-browsercontext.md | 32 ++++++++++++++++++++++++++++ docs/src/api/class-page.md | 27 +++++++++++++++++++++++ 2 files changed, 59 insertions(+) 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 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 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