Skip to content

Commit 0453112

Browse files
pujaganidiemol
andauthored
[java] Use Environment variable to set driver location (#15653)
* [java] Use environment variable to set driver locations Related to #14045 * Fix formatting * Repinning deps --------- Co-authored-by: Diego Molina <diemol@gmail.com> Co-authored-by: Diego Molina <diemol@users.noreply.github.com>
1 parent 33a673e commit 0453112

File tree

12 files changed

+168
-82
lines changed

12 files changed

+168
-82
lines changed

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ maven.install(
228228
"org.slf4j:slf4j-jdk14:2.0.17",
229229
"org.tomlj:tomlj:1.1.1",
230230
"org.zeromq:jeromq:0.6.0",
231+
"uk.org.webcompere:system-stubs-jupiter:2.1.8",
232+
"uk.org.webcompere:system-stubs-core:2.1.8",
231233
],
232234
boms = [
233235
"io.opentelemetry:opentelemetry-bom:1.50.0",

java/maven_install.json

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
3-
"__INPUT_ARTIFACTS_HASH": -952221507,
4-
"__RESOLVED_ARTIFACTS_HASH": -405645956,
3+
"__INPUT_ARTIFACTS_HASH": -1882913193,
4+
"__RESOLVED_ARTIFACTS_HASH": -76667375,
55
"artifacts": {
66
"com.beust:jcommander": {
77
"shasums": {
@@ -793,11 +793,26 @@
793793
"sources": "f04df788868c471833d4aff0c9fdced4042069efe392c768f4373c04b559f5e3"
794794
},
795795
"version": "0.1.1-beta2"
796+
},
797+
"uk.org.webcompere:system-stubs-core": {
798+
"shasums": {
799+
"jar": "9c27322cfc7043c75384ad444007b0880ca18fe7231d69bfa69616bc773cafe1",
800+
"sources": "6e6c4adf9094e0200400a5d9f8086c8a1c4a0940919fe0b30d30543b483d5687"
801+
},
802+
"version": "2.1.8"
803+
},
804+
"uk.org.webcompere:system-stubs-jupiter": {
805+
"shasums": {
806+
"jar": "9a24867a51f5d22db67d9052a06bc5dd2e9a3e273bc2ee9814620f2d9f25d0a8",
807+
"sources": "208bfe2907ab022fe206402f2ef6b1ea445f8240f072a14a49e338c1448fb2b6"
808+
},
809+
"version": "2.1.8"
796810
}
797811
},
798812
"conflict_resolution": {
799813
"com.google.errorprone:error_prone_annotations:2.36.0": "com.google.errorprone:error_prone_annotations:2.38.0",
800814
"io.projectreactor:reactor-core:3.6.2": "io.projectreactor:reactor-core:3.6.6",
815+
"net.bytebuddy:byte-buddy-agent:1.17.4": "net.bytebuddy:byte-buddy-agent:1.17.5",
801816
"org.apache.commons:commons-lang3:3.14.0": "org.apache.commons:commons-lang3:3.17.0",
802817
"org.objenesis:objenesis:3.4": "org.objenesis:objenesis:3.3",
803818
"org.reactivestreams:reactive-streams:1.0.4": "org.reactivestreams:reactive-streams:1.0.3"
@@ -1133,6 +1148,13 @@
11331148
],
11341149
"redis.clients.authentication:redis-authx-core": [
11351150
"org.slf4j:slf4j-api"
1151+
],
1152+
"uk.org.webcompere:system-stubs-core": [
1153+
"net.bytebuddy:byte-buddy",
1154+
"net.bytebuddy:byte-buddy-agent"
1155+
],
1156+
"uk.org.webcompere:system-stubs-jupiter": [
1157+
"uk.org.webcompere:system-stubs-core"
11361158
]
11371159
},
11381160
"packages": {
@@ -2901,6 +2923,20 @@
29012923
],
29022924
"redis.clients.authentication:redis-authx-core": [
29032925
"redis.clients.authentication.core"
2926+
],
2927+
"uk.org.webcompere:system-stubs-core": [
2928+
"uk.org.webcompere.systemstubs",
2929+
"uk.org.webcompere.systemstubs.environment",
2930+
"uk.org.webcompere.systemstubs.exception",
2931+
"uk.org.webcompere.systemstubs.properties",
2932+
"uk.org.webcompere.systemstubs.resource",
2933+
"uk.org.webcompere.systemstubs.security",
2934+
"uk.org.webcompere.systemstubs.stream",
2935+
"uk.org.webcompere.systemstubs.stream.input",
2936+
"uk.org.webcompere.systemstubs.stream.output"
2937+
],
2938+
"uk.org.webcompere:system-stubs-jupiter": [
2939+
"uk.org.webcompere.systemstubs.jupiter"
29042940
]
29052941
},
29062942
"repositories": {
@@ -3130,7 +3166,11 @@
31303166
"org.zeromq:jeromq",
31313167
"org.zeromq:jeromq:jar:sources",
31323168
"redis.clients.authentication:redis-authx-core",
3133-
"redis.clients.authentication:redis-authx-core:jar:sources"
3169+
"redis.clients.authentication:redis-authx-core:jar:sources",
3170+
"uk.org.webcompere:system-stubs-core",
3171+
"uk.org.webcompere:system-stubs-core:jar:sources",
3172+
"uk.org.webcompere:system-stubs-jupiter",
3173+
"uk.org.webcompere:system-stubs-jupiter:jar:sources"
31343174
]
31353175
},
31363176
"services": {

java/src/org/openqa/selenium/chrome/ChromeDriverService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class ChromeDriverService extends DriverService {
4848
*/
4949
public static final String CHROME_DRIVER_EXE_PROPERTY = "webdriver.chrome.driver";
5050

51+
public static final String CHROME_DRIVER_EXE_ENVIRONMENT_VARIABLE = "SE_CHROMEDRIVER";
52+
5153
/** System property that toggles the formatting of the timestamps of the logs */
5254
public static final String CHROME_DRIVER_READABLE_TIMESTAMP =
5355
"webdriver.chrome.readableTimestamp";
@@ -122,6 +124,10 @@ public String getDriverProperty() {
122124
return CHROME_DRIVER_EXE_PROPERTY;
123125
}
124126

127+
public String getDriverEnvironmentVariable() {
128+
return CHROME_DRIVER_EXE_ENVIRONMENT_VARIABLE;
129+
}
130+
125131
@Override
126132
public Capabilities getDefaultDriverOptions() {
127133
return new ChromeOptions();

java/src/org/openqa/selenium/edge/EdgeDriverService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public class EdgeDriverService extends DriverService {
4646
*/
4747
public static final String EDGE_DRIVER_EXE_PROPERTY = "webdriver.edge.driver";
4848

49+
public static final String EDGE_DRIVER_EXE_ENVIRONMENT_VARIABLE = "SE_EDGEDRIVER";
50+
4951
/** System property that toggles the formatting of the timestamps of the logs */
5052
public static final String EDGE_DRIVER_READABLE_TIMESTAMP = "webdriver.edge.readableTimestamp";
5153

@@ -111,6 +113,10 @@ public String getDriverProperty() {
111113
return EDGE_DRIVER_EXE_PROPERTY;
112114
}
113115

116+
public String getDriverEnvironmentVariable() {
117+
return EDGE_DRIVER_EXE_ENVIRONMENT_VARIABLE;
118+
}
119+
114120
@Override
115121
public Capabilities getDefaultDriverOptions() {
116122
return new EdgeOptions();

java/src/org/openqa/selenium/firefox/GeckoDriverService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class GeckoDriverService extends FirefoxDriverService {
4848
*/
4949
public static final String GECKO_DRIVER_EXE_PROPERTY = "webdriver.gecko.driver";
5050

51+
public static final String GECKO_DRIVER_EXE_ENVIRONMENT_VARIABLE = "SE_GECKODRIVER";
52+
5153
/**
5254
* System property that defines the location of the file where GeckoDriver should write log
5355
* messages to.
@@ -103,6 +105,10 @@ public String getDriverProperty() {
103105
return GECKO_DRIVER_EXE_PROPERTY;
104106
}
105107

108+
public String getDriverEnvironmentVariable() {
109+
return GECKO_DRIVER_EXE_ENVIRONMENT_VARIABLE;
110+
}
111+
106112
@Override
107113
public Capabilities getDefaultDriverOptions() {
108114
return new FirefoxOptions();

java/src/org/openqa/selenium/ie/InternetExplorerDriverService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public class InternetExplorerDriverService extends DriverService {
4646
*/
4747
public static final String IE_DRIVER_EXE_PROPERTY = "webdriver.ie.driver";
4848

49+
public static final String IE_DRIVER_EXE_ENVIRONMENT_VARIABLE = "SE_IEDRIVER";
50+
4951
/**
5052
* System property that defines the location of the file where IEDriverServer should write log
5153
* messages to.
@@ -98,6 +100,10 @@ public String getDriverProperty() {
98100
return IE_DRIVER_EXE_PROPERTY;
99101
}
100102

103+
public String getDriverEnvironmentVariable() {
104+
return IE_DRIVER_EXE_ENVIRONMENT_VARIABLE;
105+
}
106+
101107
@Override
102108
public Capabilities getDefaultDriverOptions() {
103109
return new InternetExplorerOptions();

java/src/org/openqa/selenium/remote/service/DriverFinder.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,20 @@ private Result getBinaryPaths() {
9696
String driverName = service.getDriverName();
9797
result = new Result(service.getExecutable());
9898
if (result.getDriverPath() == null) {
99-
result = new Result(System.getProperty(service.getDriverProperty()));
99+
result = new Result(System.getenv(service.getDriverEnvironmentVariable()));
100100
if (result.getDriverPath() == null) {
101-
List<String> arguments = toArguments();
102-
result = seleniumManager.getBinaryPaths(arguments);
103-
Require.state(options.getBrowserName(), Path.of(result.getBrowserPath()))
104-
.isExecutable();
105-
} else {
106-
LOG.fine(
107-
String.format(
108-
"Skipping Selenium Manager, path to %s found in system property: %s",
109-
driverName, result.getDriverPath()));
101+
result = new Result(System.getProperty(service.getDriverProperty()));
102+
if (result.getDriverPath() == null) {
103+
List<String> arguments = toArguments();
104+
result = seleniumManager.getBinaryPaths(arguments);
105+
Require.state(options.getBrowserName(), Path.of(result.getBrowserPath()))
106+
.isExecutable();
107+
} else {
108+
LOG.fine(
109+
String.format(
110+
"Skipping Selenium Manager, path to %s found in system property: %s",
111+
driverName, result.getDriverPath()));
112+
}
110113
}
111114
} else {
112115
LOG.fine(

java/src/org/openqa/selenium/remote/service/DriverService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ protected Capabilities getDefaultDriverOptions() {
154154
return null;
155155
}
156156

157+
public String getDriverEnvironmentVariable() {
158+
return null;
159+
}
160+
157161
protected @Nullable File getDriverExecutable() {
158162
return null;
159163
}

java/src/org/openqa/selenium/safari/SafariDriverService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class SafariDriverService extends DriverService {
4949
*/
5050
public static final String SAFARI_DRIVER_EXE_PROPERTY = "webdriver.safari.driver";
5151

52+
public static final String SAFARI_DRIVER_EXE_ENVIRONMENT_VARIABLE = "SE_SAFARIDRIVER";
53+
5254
public static final String SAFARI_DRIVER_LOGGING = "webdriver.safari.logging";
5355

5456
private static final File SAFARI_DRIVER_EXECUTABLE = new File("/usr/bin/safaridriver");
@@ -84,6 +86,10 @@ public String getDriverProperty() {
8486
return SAFARI_DRIVER_EXE_PROPERTY;
8587
}
8688

89+
public String getDriverEnvironmentVariable() {
90+
return SAFARI_DRIVER_EXE_ENVIRONMENT_VARIABLE;
91+
}
92+
8793
public File getDriverExecutable() {
8894
return SAFARI_DRIVER_EXECUTABLE;
8995
}

java/test/org/openqa/selenium/remote/service/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ java_test_suite(
1212
artifact("org.junit.jupiter:junit-jupiter-api"),
1313
artifact("org.assertj:assertj-core"),
1414
artifact("org.mockito:mockito-core"),
15+
artifact("uk.org.webcompere:system-stubs-jupiter"),
16+
artifact("uk.org.webcompere:system-stubs-core"),
1517
] + JUNIT5_DEPS,
1618
)

0 commit comments

Comments
 (0)