1
0
mirror of synced 2026-07-06 16:40:01 +00:00

feat: accept driver env in Playwright.create() (#480)

This commit is contained in:
Yury Semikhatsky
2021-06-09 16:17:02 -07:00
committed by GitHub
parent e83ef2b1c0
commit 87ad579deb
10 changed files with 130 additions and 25 deletions
@@ -18,6 +18,7 @@ package com.microsoft.playwright.impl;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
/**
* This class provides access to playwright-cli. It can be either preinstalled
@@ -32,16 +33,23 @@ public abstract class Driver {
PreinstalledDriver(Path driverDir) {
this.driverDir = driverDir;
}
@Override
protected void initialize(Map<String, String> env) {
// no-op
}
@Override
Path driverDir() {
return driverDir;
}
}
public static synchronized Path ensureDriverInstalled() {
public static synchronized Path ensureDriverInstalled(Map<String, String> env) {
if (instance == null) {
try {
instance = createDriver();
instance.initialize(env);
} catch (Exception exception) {
throw new RuntimeException("Failed to create driver", exception);
}
@@ -50,6 +58,8 @@ public abstract class Driver {
return instance.driverDir().resolve(name);
}
protected abstract void initialize(Map<String, String> env) throws Exception;
protected String cliFileName() {
return System.getProperty("os.name").toLowerCase().contains("windows") ?
"playwright.cmd" : "playwright.sh";