Skip to content

Commit 470df42

Browse files
authored
feat: roll 1.32 driver, implement waitForCondition (#1237)
* Rolled recent driver * Implemented waitForCondition in Page and BrowserContext #1208 Fixes #1228
1 parent b260125 commit 470df42

28 files changed

Lines changed: 953 additions & 562 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Playwright is a Java library to automate [Chromium](https://www.chromium.org/Hom
1111

1212
| | Linux | macOS | Windows |
1313
| :--- | :---: | :---: | :---: |
14-
| Chromium <!-- GEN:chromium-version -->111.0.5563.64<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
14+
| Chromium <!-- GEN:chromium-version -->112.0.5615.29<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
1515
| WebKit <!-- GEN:webkit-version -->16.4<!-- GEN:stop --> ||||
16-
| Firefox <!-- GEN:firefox-version -->109.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
16+
| Firefox <!-- GEN:firefox-version -->111.0<!-- GEN:stop --> | :white_check_mark: | :white_check_mark: | :white_check_mark: |
1717

1818
Headless execution is supported for all the browsers on all platforms. Check out [system requirements](https://playwright.dev/java/docs/next/intro/#system-requirements) for details.
1919

playwright/src/main/java/com/microsoft/playwright/BrowserContext.java

Lines changed: 94 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.nio.file.Path;
2121
import java.util.*;
2222
import java.util.function.Consumer;
23+
import java.util.function.BooleanSupplier;
2324
import java.util.function.Predicate;
2425
import java.util.regex.Pattern;
2526

@@ -175,18 +176,6 @@ public RouteOptions setTimes(int times) {
175176
}
176177
}
177178
class RouteFromHAROptions {
178-
/**
179-
* Optional setting to control resource content management. If {@code omit} is specified, content is not persisted. If
180-
* {@code attach} is specified, resources are persisted as separate files or entries in the ZIP archive. If {@code embed}
181-
* is specified, content is stored inline the HAR file
182-
*/
183-
public HarContentPolicy content;
184-
/**
185-
* When set to {@code minimal}, only record information necessary for routing from HAR. This omits sizes, timing, page,
186-
* cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to {@code
187-
* minimal}.
188-
*/
189-
public HarMode mode;
190179
/**
191180
* <ul>
192181
* <li> If set to 'abort' any request not found in the HAR file will be aborted.</li>
@@ -202,29 +191,22 @@ class RouteFromHAROptions {
202191
*/
203192
public Boolean update;
204193
/**
205-
* A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
206-
* will be served from the HAR file. If not specified, all requests are served from the HAR file.
194+
* Optional setting to control resource content management. If {@code attach} is specified, resources are persisted as
195+
* separate files or entries in the ZIP archive. If {@code embed} is specified, content is stored inline the HAR file.
207196
*/
208-
public Object url;
209-
210-
/**
211-
* Optional setting to control resource content management. If {@code omit} is specified, content is not persisted. If
212-
* {@code attach} is specified, resources are persisted as separate files or entries in the ZIP archive. If {@code embed}
213-
* is specified, content is stored inline the HAR file
214-
*/
215-
public RouteFromHAROptions setContent(HarContentPolicy content) {
216-
this.content = content;
217-
return this;
218-
}
197+
public RouteFromHarUpdateContentPolicy updateContent;
219198
/**
220199
* When set to {@code minimal}, only record information necessary for routing from HAR. This omits sizes, timing, page,
221200
* cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to {@code
222201
* minimal}.
223202
*/
224-
public RouteFromHAROptions setMode(HarMode mode) {
225-
this.mode = mode;
226-
return this;
227-
}
203+
public HarMode updateMode;
204+
/**
205+
* A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
206+
* will be served from the HAR file. If not specified, all requests are served from the HAR file.
207+
*/
208+
public Object url;
209+
228210
/**
229211
* <ul>
230212
* <li> If set to 'abort' any request not found in the HAR file will be aborted.</li>
@@ -245,6 +227,23 @@ public RouteFromHAROptions setUpdate(boolean update) {
245227
this.update = update;
246228
return this;
247229
}
230+
/**
231+
* Optional setting to control resource content management. If {@code attach} is specified, resources are persisted as
232+
* separate files or entries in the ZIP archive. If {@code embed} is specified, content is stored inline the HAR file.
233+
*/
234+
public RouteFromHAROptions setUpdateContent(RouteFromHarUpdateContentPolicy updateContent) {
235+
this.updateContent = updateContent;
236+
return this;
237+
}
238+
/**
239+
* When set to {@code minimal}, only record information necessary for routing from HAR. This omits sizes, timing, page,
240+
* cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to {@code
241+
* minimal}.
242+
*/
243+
public RouteFromHAROptions setUpdateMode(HarMode updateMode) {
244+
this.updateMode = updateMode;
245+
return this;
246+
}
248247
/**
249248
* A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
250249
* will be served from the HAR file. If not specified, all requests are served from the HAR file.
@@ -278,6 +277,24 @@ public StorageStateOptions setPath(Path path) {
278277
return this;
279278
}
280279
}
280+
class WaitForConditionOptions {
281+
/**
282+
* Maximum time to wait for in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The
283+
* default value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or
284+
* {@link Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
285+
*/
286+
public Double timeout;
287+
288+
/**
289+
* Maximum time to wait for in milliseconds. Defaults to {@code 30000} (30 seconds). Pass {@code 0} to disable timeout. The
290+
* default value can be changed by using the {@link BrowserContext#setDefaultTimeout BrowserContext.setDefaultTimeout()} or
291+
* {@link Page#setDefaultTimeout Page.setDefaultTimeout()} methods.
292+
*/
293+
public WaitForConditionOptions setTimeout(double timeout) {
294+
this.timeout = timeout;
295+
return this;
296+
}
297+
}
281298
class WaitForPageOptions {
282299
/**
283300
* Receives the {@code Page} object and resolves to truthy value when the waiting should resolve.
@@ -1177,6 +1194,54 @@ default void unroute(Predicate<String> url) {
11771194
* @since v1.8
11781195
*/
11791196
void unroute(Predicate<String> url, Consumer<Route> handler);
1197+
/**
1198+
* The method will block until the condition returns true. All Playwright events will be dispatched while the method is
1199+
* waiting for the condition.
1200+
*
1201+
* <p> **Usage**
1202+
*
1203+
* <p> Use the method to wait for a condition that depends on page events:
1204+
* <pre>{@code
1205+
* List<String> failedUrls = new ArrayList<>();
1206+
* context.onResponse(response -> {
1207+
* if (!response.ok()) {
1208+
* failedUrls.add(response.url());
1209+
* }
1210+
* });
1211+
* page1.getByText("Create user").click();
1212+
* page2.getByText("Submit button").click();
1213+
* context.waitForCondition(() -> failedUrls.size() > 3);
1214+
* }</pre>
1215+
*
1216+
* @param condition Condition to wait for.
1217+
* @since v1.32
1218+
*/
1219+
default void waitForCondition(BooleanSupplier condition) {
1220+
waitForCondition(condition, null);
1221+
}
1222+
/**
1223+
* The method will block until the condition returns true. All Playwright events will be dispatched while the method is
1224+
* waiting for the condition.
1225+
*
1226+
* <p> **Usage**
1227+
*
1228+
* <p> Use the method to wait for a condition that depends on page events:
1229+
* <pre>{@code
1230+
* List<String> failedUrls = new ArrayList<>();
1231+
* context.onResponse(response -> {
1232+
* if (!response.ok()) {
1233+
* failedUrls.add(response.url());
1234+
* }
1235+
* });
1236+
* page1.getByText("Create user").click();
1237+
* page2.getByText("Submit button").click();
1238+
* context.waitForCondition(() -> failedUrls.size() > 3);
1239+
* }</pre>
1240+
*
1241+
* @param condition Condition to wait for.
1242+
* @since v1.32
1243+
*/
1244+
void waitForCondition(BooleanSupplier condition, WaitForConditionOptions options);
11801245
/**
11811246
* Performs action and waits for a new {@code Page} to be created in the context. If predicate is provided, it passes
11821247
* {@code Page} value into the {@code predicate} function and waits for {@code predicate(event)} to return a truthy value.

0 commit comments

Comments
 (0)