fix(api): update waitForRequest/Response predicate to accept Request/… (#224)
This commit is contained in:
@@ -2391,20 +2391,20 @@ public interface Page {
|
||||
* <p> Shortcut for main frame's [{@code method: Frame.waitForNavigation}].
|
||||
*/
|
||||
Response waitForNavigation(Runnable code, WaitForNavigationOptions options);
|
||||
Request waitForRequest(Runnable code);
|
||||
default Request waitForRequest(Runnable code) { return waitForRequest(code, (Predicate<Request>) null, null); }
|
||||
default Request waitForRequest(Runnable code, String urlGlob) { return waitForRequest(code, urlGlob, null); }
|
||||
default Request waitForRequest(Runnable code, Pattern urlPattern) { return waitForRequest(code, urlPattern, null); }
|
||||
default Request waitForRequest(Runnable code, Predicate<String> urlPredicate) { return waitForRequest(code, urlPredicate, null); }
|
||||
default Request waitForRequest(Runnable code, Predicate<Request> predicate) { return waitForRequest(code, predicate, null); }
|
||||
Request waitForRequest(Runnable code, String urlGlob, WaitForRequestOptions options);
|
||||
Request waitForRequest(Runnable code, Pattern urlPattern, WaitForRequestOptions options);
|
||||
Request waitForRequest(Runnable code, Predicate<String> urlPredicate, WaitForRequestOptions options);
|
||||
Response waitForResponse(Runnable code);
|
||||
Request waitForRequest(Runnable code, Predicate<Request> predicate, WaitForRequestOptions options);
|
||||
default Response waitForResponse(Runnable code) { return waitForResponse(code, (Predicate<Response>) null, null); }
|
||||
default Response waitForResponse(Runnable code, String urlGlob) { return waitForResponse(code, urlGlob, null); }
|
||||
default Response waitForResponse(Runnable code, Pattern urlPattern) { return waitForResponse(code, urlPattern, null); }
|
||||
default Response waitForResponse(Runnable code, Predicate<String> urlPredicate) { return waitForResponse(code, urlPredicate, null); }
|
||||
default Response waitForResponse(Runnable code, Predicate<Response> predicate) { return waitForResponse(code, predicate, null); }
|
||||
Response waitForResponse(Runnable code, String urlGlob, WaitForResponseOptions options);
|
||||
Response waitForResponse(Runnable code, Pattern urlPattern, WaitForResponseOptions options);
|
||||
Response waitForResponse(Runnable code, Predicate<String> urlPredicate, WaitForResponseOptions options);
|
||||
Response waitForResponse(Runnable code, Predicate<Response> predicate, WaitForResponseOptions options);
|
||||
default ElementHandle waitForSelector(String selector) {
|
||||
return waitForSelector(selector, null);
|
||||
}
|
||||
|
||||
@@ -1180,11 +1180,6 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
return withLogging("Page.waitForNavigation", () -> waitForNavigationImpl(code, options));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request waitForRequest(Runnable code) {
|
||||
return waitForRequest(code, UrlMatcher.any(), null);
|
||||
}
|
||||
|
||||
Response waitForNavigationImpl(Runnable code, WaitForNavigationOptions options) {
|
||||
Frame.WaitForNavigationOptions frameOptions = new Frame.WaitForNavigationOptions();
|
||||
if (options != null) {
|
||||
@@ -1288,34 +1283,30 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public Request waitForRequest(Runnable code, String urlGlob, WaitForRequestOptions options) {
|
||||
return waitForRequest(code, new UrlMatcher(urlGlob), options);
|
||||
return waitForRequest(code, toRequestPredicate(new UrlMatcher(urlGlob)), options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request waitForRequest(Runnable code, Pattern urlPattern, WaitForRequestOptions options) {
|
||||
return waitForRequest(code, new UrlMatcher(urlPattern), options);
|
||||
return waitForRequest(code, toRequestPredicate(new UrlMatcher(urlPattern)), options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Request waitForRequest(Runnable code, Predicate<String> urlPredicate, WaitForRequestOptions options) {
|
||||
return waitForRequest(code, new UrlMatcher(urlPredicate), options);
|
||||
public Request waitForRequest(Runnable code, Predicate<Request> predicate, WaitForRequestOptions options) {
|
||||
return withLogging("Page.waitForRequest", () -> waitForRequestImpl(code, predicate, options));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response waitForResponse(Runnable code) {
|
||||
return waitForResponse(code, UrlMatcher.any(), null);
|
||||
private static Predicate<Request> toRequestPredicate(UrlMatcher matcher) {
|
||||
return request -> matcher.test(request.url());
|
||||
}
|
||||
|
||||
private Request waitForRequest(Runnable code, UrlMatcher matcher, WaitForRequestOptions options) {
|
||||
return withLogging("Page.waitForRequest", () -> waitForRequestImpl(code, matcher, options));
|
||||
}
|
||||
|
||||
private Request waitForRequestImpl(Runnable code, UrlMatcher matcher, WaitForRequestOptions options) {
|
||||
private Request waitForRequestImpl(Runnable code, Predicate<Request> predicate, WaitForRequestOptions options) {
|
||||
if (options == null) {
|
||||
options = new WaitForRequestOptions();
|
||||
}
|
||||
List<Waitable<Request>> waitables = new ArrayList<>();
|
||||
waitables.add(new WaitableEvent<>(listeners, EventType.REQUEST, e -> matcher.test(((Request) e.data()).url()))
|
||||
waitables.add(new WaitableEvent<>(listeners, EventType.REQUEST,
|
||||
e -> predicate == null || predicate.test(((Request) e.data())))
|
||||
.apply(event -> (Request) event.data()));
|
||||
waitables.add(createWaitForCloseHelper());
|
||||
waitables.add(createWaitableTimeout(options.timeout));
|
||||
@@ -1324,29 +1315,30 @@ public class PageImpl extends ChannelOwner implements Page {
|
||||
|
||||
@Override
|
||||
public Response waitForResponse(Runnable code, String urlGlob, WaitForResponseOptions options) {
|
||||
return waitForResponse(code, new UrlMatcher(urlGlob), options);
|
||||
return waitForResponse(code, toResponsePredicate(new UrlMatcher(urlGlob)), options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response waitForResponse(Runnable code, Pattern urlPattern, WaitForResponseOptions options) {
|
||||
return waitForResponse(code, new UrlMatcher(urlPattern), options);
|
||||
return waitForResponse(code, toResponsePredicate(new UrlMatcher(urlPattern)), options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response waitForResponse(Runnable code, Predicate<String> urlPredicate, WaitForResponseOptions options) {
|
||||
return waitForResponse(code, new UrlMatcher(urlPredicate), options);
|
||||
public Response waitForResponse(Runnable code, Predicate<Response> predicate, WaitForResponseOptions options) {
|
||||
return withLogging("Page.waitForResponse", () -> waitForResponseImpl(code, predicate, options));
|
||||
}
|
||||
|
||||
private Response waitForResponse(Runnable code, UrlMatcher matcher, WaitForResponseOptions options) {
|
||||
return withLogging("Page.waitForResponse", () -> waitForonseImpl(code, matcher, options));
|
||||
private static Predicate<Response> toResponsePredicate(UrlMatcher matcher) {
|
||||
return response -> matcher.test(response.url());
|
||||
}
|
||||
|
||||
private Response waitForonseImpl(Runnable code, UrlMatcher matcher, WaitForResponseOptions options) {
|
||||
private Response waitForResponseImpl(Runnable code, Predicate<Response> predicate, WaitForResponseOptions options) {
|
||||
if (options == null) {
|
||||
options = new WaitForResponseOptions();
|
||||
}
|
||||
List<Waitable<Response>> waitables = new ArrayList<>();
|
||||
waitables.add(new WaitableEvent<>(listeners, EventType.RESPONSE, e -> matcher.test(((Response) e.data()).url()))
|
||||
waitables.add(new WaitableEvent<>(listeners, EventType.RESPONSE,
|
||||
e -> predicate == null || predicate.test(((Response) e.data())))
|
||||
.apply(event -> (Response) event.data()));
|
||||
waitables.add(createWaitForCloseHelper());
|
||||
waitables.add(createWaitableTimeout(options.timeout));
|
||||
|
||||
@@ -46,7 +46,7 @@ public class TestPageWaitForRequest extends TestBase {
|
||||
" fetch('/digits/2.png');\n" +
|
||||
" fetch('/digits/3.png');\n" +
|
||||
"}");
|
||||
}, url -> url.equals(server.PREFIX + "/digits/2.png"));
|
||||
}, r -> r.url().equals(server.PREFIX + "/digits/2.png"));
|
||||
assertEquals(server.PREFIX + "/digits/2.png", request.url());
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class TestPageWaitForRequest extends TestBase {
|
||||
void shouldRespectDefaultTimeout() {
|
||||
page.setDefaultTimeout(1);
|
||||
try {
|
||||
page.waitForRequest(() -> {}, url -> false);
|
||||
page.waitForRequest(() -> {}, request -> false);
|
||||
fail("did not throw");
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Timeout"), e.getMessage());
|
||||
|
||||
@@ -43,7 +43,7 @@ public class TestPageWaitForResponse extends TestBase {
|
||||
" fetch('/digits/2.png');\n" +
|
||||
" fetch('/digits/3.png');\n" +
|
||||
"}");
|
||||
}, url -> url.equals(server.PREFIX + "/digits/2.png"));
|
||||
}, r -> r.url().equals(server.PREFIX + "/digits/2.png"));
|
||||
assertEquals(server.PREFIX + "/digits/2.png", response.url());
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class TestPageWaitForResponse extends TestBase {
|
||||
" fetch('/digits/2.png');\n" +
|
||||
" fetch('/digits/3.png');\n" +
|
||||
"}");
|
||||
}, url -> url.equals(server.PREFIX + "/digits/2.png"));
|
||||
}, r -> r.url().equals(server.PREFIX + "/digits/2.png"));
|
||||
assertEquals(server.PREFIX + "/digits/2.png", response.url());
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class TestPageWaitForResponse extends TestBase {
|
||||
void shouldRespectDefaultTimeout() {
|
||||
page.setDefaultTimeout(1);
|
||||
try {
|
||||
page.waitForResponse(() -> {}, url -> false);
|
||||
page.waitForResponse(() -> {}, response -> false);
|
||||
fail("did not throw");
|
||||
} catch (PlaywrightException e) {
|
||||
assertTrue(e.getMessage().contains("Timeout"), e.getMessage());
|
||||
|
||||
@@ -583,22 +583,22 @@ class Method extends Element {
|
||||
customSignature.put("WebSocket.waitForEvent", new String[] {});
|
||||
|
||||
customSignature.put("Page.waitForRequest", new String[] {
|
||||
"Request waitForRequest(Runnable code);",
|
||||
"default Request waitForRequest(Runnable code) { return waitForRequest(code, (Predicate<Request>) null, null); }",
|
||||
"default Request waitForRequest(Runnable code, String urlGlob) { return waitForRequest(code, urlGlob, null); }",
|
||||
"default Request waitForRequest(Runnable code, Pattern urlPattern) { return waitForRequest(code, urlPattern, null); }",
|
||||
"default Request waitForRequest(Runnable code, Predicate<String> urlPredicate) { return waitForRequest(code, urlPredicate, null); }",
|
||||
"default Request waitForRequest(Runnable code, Predicate<Request> predicate) { return waitForRequest(code, predicate, null); }",
|
||||
"Request waitForRequest(Runnable code, String urlGlob, WaitForRequestOptions options);",
|
||||
"Request waitForRequest(Runnable code, Pattern urlPattern, WaitForRequestOptions options);",
|
||||
"Request waitForRequest(Runnable code, Predicate<String> urlPredicate, WaitForRequestOptions options);"
|
||||
"Request waitForRequest(Runnable code, Predicate<Request> predicate, WaitForRequestOptions options);"
|
||||
});
|
||||
customSignature.put("Page.waitForResponse", new String[] {
|
||||
"Response waitForResponse(Runnable code);",
|
||||
"default Response waitForResponse(Runnable code) { return waitForResponse(code, (Predicate<Response>) null, null); }",
|
||||
"default Response waitForResponse(Runnable code, String urlGlob) { return waitForResponse(code, urlGlob, null); }",
|
||||
"default Response waitForResponse(Runnable code, Pattern urlPattern) { return waitForResponse(code, urlPattern, null); }",
|
||||
"default Response waitForResponse(Runnable code, Predicate<String> urlPredicate) { return waitForResponse(code, urlPredicate, null); }",
|
||||
"default Response waitForResponse(Runnable code, Predicate<Response> predicate) { return waitForResponse(code, predicate, null); }",
|
||||
"Response waitForResponse(Runnable code, String urlGlob, WaitForResponseOptions options);",
|
||||
"Response waitForResponse(Runnable code, Pattern urlPattern, WaitForResponseOptions options);",
|
||||
"Response waitForResponse(Runnable code, Predicate<String> urlPredicate, WaitForResponseOptions options);"
|
||||
"Response waitForResponse(Runnable code, Predicate<Response> predicate, WaitForResponseOptions options);"
|
||||
});
|
||||
|
||||
String[] waitForNavigation = {
|
||||
@@ -665,10 +665,6 @@ class Method extends Element {
|
||||
}
|
||||
|
||||
private static Set<String> skipJavadoc = new HashSet<>(asList(
|
||||
"BrowserContext.waitForEvent.optionsOrPredicate",
|
||||
"Page.waitForEvent.optionsOrPredicate",
|
||||
"WebSocket.waitForEvent.optionsOrPredicate",
|
||||
"Page.frame.options",
|
||||
"Page.waitForRequest",
|
||||
"Page.waitForResponse"
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user