mirror of
https://github.com/microsoft/playwright-java.git
synced 2025-12-28 10:20:45 +00:00
chore: only log har when pw:api is enabled (#977)
This commit is contained in:
parent
9fac877892
commit
44cb76d92c
@ -26,6 +26,7 @@ import java.nio.file.Path;
|
||||
import java.util.Base64;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.microsoft.playwright.impl.LoggingSupport.isApiLoggingEnabled;
|
||||
import static com.microsoft.playwright.impl.LoggingSupport.logApi;
|
||||
import static com.microsoft.playwright.impl.Serialization.fromNameValues;
|
||||
import static com.microsoft.playwright.impl.Serialization.gson;
|
||||
@ -66,7 +67,9 @@ public class HARRouter {
|
||||
String action = response.get("action").getAsString();
|
||||
if ("redirect".equals(action)) {
|
||||
String redirectURL = response.get("redirectURL").getAsString();
|
||||
logApi("HAR: " + route.request().url() + " redirected to " + redirectURL);
|
||||
if (isApiLoggingEnabled()) {
|
||||
logApi("HAR: " + route.request().url() + " redirected to " + redirectURL);
|
||||
}
|
||||
((RouteImpl) route).redirectNavigationRequest(redirectURL);
|
||||
return;
|
||||
}
|
||||
@ -83,7 +86,9 @@ public class HARRouter {
|
||||
}
|
||||
|
||||
if ("error".equals(action)) {
|
||||
logApi("HAR: " + response.get("message").getAsString());
|
||||
if (isApiLoggingEnabled()) {
|
||||
logApi("HAR: " + response.get("message").getAsString());
|
||||
}
|
||||
// Report the error, but fall through to the default handler.
|
||||
}
|
||||
|
||||
|
||||
@ -60,6 +60,10 @@ class LoggingSupport {
|
||||
System.err.println(timestamp + " " + message);
|
||||
}
|
||||
|
||||
static boolean isApiLoggingEnabled() {
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
static void logApi(String message) {
|
||||
// This matches log format produced by the server.
|
||||
logWithTimestamp("pw:api " + message);
|
||||
|
||||
@ -39,9 +39,6 @@ class Router {
|
||||
}
|
||||
|
||||
boolean handle(RouteImpl route) {
|
||||
if (times != null && times <= 0) {
|
||||
return false;
|
||||
}
|
||||
if (!matcher.test(route.request().url())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -326,8 +326,7 @@ public class TestBrowserContextHar extends TestBase {
|
||||
assertEquals("3", page2.evaluate(fetchFunction, "3"));
|
||||
assertEquals("3", page2.evaluate(fetchFunction, "3"));
|
||||
try {
|
||||
Object result = page2.evaluate(fetchFunction, "4");
|
||||
System.out.println(result);
|
||||
page2.evaluate(fetchFunction, "4");
|
||||
fail("did not throw");
|
||||
} catch (PlaywrightException e) {
|
||||
}
|
||||
|
||||
@ -133,10 +133,14 @@ public class TestPageRequestFallback extends TestBase {
|
||||
@Test
|
||||
void shouldChainOnce() {
|
||||
page.route("**/empty.html", route -> {
|
||||
System.out.println("before fulfill");
|
||||
route.fulfill(new Route.FulfillOptions().setStatus(200).setBody("fulfilled one"));
|
||||
System.out.println("after fulfill");
|
||||
}, new Page.RouteOptions().setTimes(1));
|
||||
page.route("**/empty.html", route -> {
|
||||
System.out.println("before fallback");
|
||||
route.fallback();
|
||||
System.out.println("after fallback");
|
||||
}, new Page.RouteOptions().setTimes(1));
|
||||
Response response = page.navigate(server.EMPTY_PAGE);
|
||||
assertEquals("fulfilled one", response.text());
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user