Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java][sm] Configure Selenium Manager environment from System Properties #13858

Merged
merged 3 commits into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 22 additions & 7 deletions java/src/org/openqa/selenium/manager/SeleniumManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.nio.file.Paths;
import java.time.Duration;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.openqa.selenium.Beta;
Expand Down Expand Up @@ -62,6 +63,7 @@ public class SeleniumManager {
private static final String CACHE_PATH_ENV = "SE_CACHE_PATH";
private static final String BETA_PREFIX = "0.";
private static final String EXE = ".exe";
private static final String SE_ENV_PREFIX = "SE_";

private static volatile SeleniumManager manager;
private final String managerPath = System.getenv("SE_MANAGER_PATH");
Expand Down Expand Up @@ -119,8 +121,21 @@ private static Result runCommand(Path binary, List<String> arguments) {
String output;
int code;
try {
ExternalProcess.Builder processBuilder = ExternalProcess.builder();

Properties properties = System.getProperties();
for (String name : properties.stringPropertyNames()) {
if (name.startsWith(SE_ENV_PREFIX)) {
// read property with 'default' value due to concurrency
String value = properties.getProperty(name, "");
if (!value.isEmpty()) {
processBuilder.environment(name, value);
}
}
}
ExternalProcess process =
ExternalProcess.builder().command(binary.toAbsolutePath().toString(), arguments).start();
processBuilder.command(binary.toAbsolutePath().toString(), arguments).start();

if (!process.waitFor(Duration.ofHours(1))) {
LOG.warning("Selenium Manager did not exit, shutting it down");
process.shutdown();
Expand Down Expand Up @@ -240,13 +255,13 @@ private Level getLogLevel() {
}

private Path getBinaryInCache(String binaryName) throws IOException {
String cachePath = DEFAULT_CACHE_PATH.replace(HOME, System.getProperty("user.home"));

// Look for cache path as env
String cachePathEnv = System.getenv(CACHE_PATH_ENV);
if (cachePathEnv != null) {
cachePath = cachePathEnv;
}
// Look for cache path as system property or env
String cachePath = System.getProperty(CACHE_PATH_ENV, "");
if (cachePath.isEmpty()) cachePath = System.getenv(CACHE_PATH_ENV);
if (cachePath == null) cachePath = DEFAULT_CACHE_PATH;

cachePath = cachePath.replace(HOME, System.getProperty("user.home"));

// If cache path is not writable, SM will be extracted to a temporal folder
Path cacheParent = Paths.get(cachePath);
Expand Down