2020import java .nio .file .Path ;
2121import java .util .*;
2222import java .util .function .Consumer ;
23+ import java .util .function .BooleanSupplier ;
2324import java .util .function .Predicate ;
2425import 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