mirror of
https://github.com/microsoft/playwright-java.git
synced 2025-12-29 02:40:42 +00:00
parent
a006d51872
commit
6b30c0b3d2
@ -65,6 +65,25 @@ public abstract class Driver {
|
||||
return driverDir().resolve(cliFileName);
|
||||
}
|
||||
|
||||
public static void setRequiredEnvironmentVariables(ProcessBuilder pb) {
|
||||
if (!pb.environment().containsKey("PW_CLI_TARGET_LANG")) {
|
||||
pb.environment().put("PW_CLI_TARGET_LANG", "java");
|
||||
pb.environment().put("PW_CLI_TARGET_LANG_VERSION", getMajorJavaVersion());
|
||||
}
|
||||
}
|
||||
|
||||
private static String getMajorJavaVersion() {
|
||||
String version = System.getProperty("java.version");
|
||||
if (version.startsWith("1.")) {
|
||||
return version.substring(2, 3);
|
||||
}
|
||||
int dot = version.indexOf(".");
|
||||
if (dot != -1) {
|
||||
return version.substring(0, dot);
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
private static Driver createDriver() throws Exception {
|
||||
String pathFromProperty = System.getProperty("playwright.cli.dir");
|
||||
if (pathFromProperty != null) {
|
||||
|
||||
@ -32,9 +32,7 @@ public class CLI {
|
||||
Path driver = Driver.ensureDriverInstalled(Collections.emptyMap());
|
||||
ProcessBuilder pb = new ProcessBuilder(driver.toString());
|
||||
pb.command().addAll(asList(args));
|
||||
if (!pb.environment().containsKey("PW_CLI_TARGET_LANG")) {
|
||||
pb.environment().put("PW_CLI_TARGET_LANG", "java");
|
||||
}
|
||||
Driver.setRequiredEnvironmentVariables(pb);
|
||||
String version = Playwright.class.getPackage().getImplementationVersion();
|
||||
if (version != null) {
|
||||
pb.environment().put("PW_CLI_DISPLAY_VERSION", version);
|
||||
|
||||
@ -41,6 +41,7 @@ public class PlaywrightImpl extends ChannelOwner implements Playwright {
|
||||
ProcessBuilder pb = new ProcessBuilder(driver.toString(), "run-driver");
|
||||
pb.redirectError(ProcessBuilder.Redirect.INHERIT);
|
||||
pb.environment().putAll(env);
|
||||
Driver.setRequiredEnvironmentVariables(pb);
|
||||
Process p = pb.start();
|
||||
Connection connection = new Connection(new PipeTransport(p.getInputStream(), p.getOutputStream()));
|
||||
PlaywrightImpl result = connection.initializePlaywright();
|
||||
|
||||
@ -16,6 +16,25 @@ import static java.util.Arrays.asList;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestGlobalFetch extends TestBase {
|
||||
@Test
|
||||
void shouldHaveJavaInDefaultUesrAgent() throws ExecutionException, InterruptedException {
|
||||
APIRequestContext request = playwright.request().newContext(new APIRequest.NewContextOptions());
|
||||
Future<Server.Request> serverRequest = server.futureRequest("/empty.html");
|
||||
APIResponse response = request.get(server.EMPTY_PAGE);
|
||||
assertTrue(response.ok());
|
||||
assertEquals(server.EMPTY_PAGE, response.url());
|
||||
String version = System.getProperty("java.version");
|
||||
if (version.startsWith("1.")) {
|
||||
version = version.substring(2, 3);
|
||||
} else {
|
||||
int dot = version.indexOf(".");
|
||||
if (dot != -1) {
|
||||
version = version.substring(0, dot);
|
||||
}
|
||||
}
|
||||
assertTrue(serverRequest.get().headers.get("user-agent").get(0).contains("java/" + version));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fetchShouldWork() {
|
||||
APIRequestContext request = playwright.request().newContext();
|
||||
|
||||
@ -1 +1 @@
|
||||
1.18.0-beta-1642115083000
|
||||
1.18.0-rc1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user