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

https://github.com/microsoft/playwright-java/issues/1228
This commit is contained in:
Yury Semikhatsky 2023-03-17 13:02:59 -07:00 committed by GitHub
parent f484b833ae
commit a61b544932
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 0 deletions

View File

@ -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`]. 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 ## async method: BrowserContext.waitForEvent
* since: v1.8 * since: v1.8
* langs: js, python * langs: js, python

View File

@ -4784,6 +4784,33 @@ class FrameExamples
### option: Page.waitForSelector.timeout = %%-input-timeout-js-%% ### option: Page.waitForSelector.timeout = %%-input-timeout-js-%%
* since: v1.8 * 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 ## async method: Page.waitForTimeout
* since: v1.8 * since: v1.8