Skip to content

Commit f75ea68

Browse files
committed
[java] update logging and errors for driver management
1 parent 34adf3e commit f75ea68

File tree

7 files changed

+38
-30
lines changed

7 files changed

+38
-30
lines changed

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,10 @@ private static ChromeDriverCommandExecutor generateExecutor(
9696
Require.nonNull("Driver service", service);
9797
Require.nonNull("Driver options", options);
9898
Require.nonNull("Driver clientConfig", clientConfig);
99-
if (service.getExecutable() == null) {
100-
Result result = DriverFinder.getPath(service, options);
101-
service.setExecutable(result.getDriverPath());
102-
if (result.getBrowserPath() != null && !result.getBrowserPath().isEmpty()) {
103-
options.setBinary(result.getBrowserPath());
104-
}
99+
Result result = DriverFinder.getPath(service, options);
100+
service.setExecutable(result.getDriverPath());
101+
if (result.getBrowserPath() != null && !result.getBrowserPath().isEmpty()) {
102+
options.setBinary(result.getBrowserPath());
105103
}
106104
return new ChromeDriverCommandExecutor(service, clientConfig);
107105
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,10 @@ private static EdgeDriverCommandExecutor generateExecutor(
6868
Require.nonNull("Driver service", service);
6969
Require.nonNull("Driver options", options);
7070
Require.nonNull("Driver clientConfig", clientConfig);
71-
if (service.getExecutable() == null) {
72-
Result result = DriverFinder.getPath(service, options);
73-
service.setExecutable(result.getDriverPath());
74-
if (result.getBrowserPath() != null && !result.getBrowserPath().isEmpty()) {
75-
options.setBinary(result.getBrowserPath());
76-
}
71+
Result result = DriverFinder.getPath(service, options);
72+
service.setExecutable(result.getDriverPath());
73+
if (result.getBrowserPath() != null && !result.getBrowserPath().isEmpty()) {
74+
options.setBinary(result.getBrowserPath());
7775
}
7876
return new EdgeDriverCommandExecutor(service, clientConfig);
7977
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,10 @@ private static FirefoxDriverCommandExecutor generateExecutor(
138138
Require.nonNull("Driver service", service);
139139
Require.nonNull("Driver options", options);
140140
Require.nonNull("Driver clientConfig", clientConfig);
141-
if (service.getExecutable() == null) {
142-
Result result = DriverFinder.getPath(service, options);
143-
service.setExecutable(result.getDriverPath());
144-
if (result.getBrowserPath() != null && !result.getBrowserPath().isEmpty()) {
145-
options.setBinary(result.getBrowserPath());
146-
}
141+
Result result = DriverFinder.getPath(service, options);
142+
service.setExecutable(result.getDriverPath());
143+
if (result.getBrowserPath() != null && !result.getBrowserPath().isEmpty()) {
144+
options.setBinary(result.getBrowserPath());
147145
}
148146
return new FirefoxDriverCommandExecutor(service, clientConfig);
149147
}

java/src/org/openqa/selenium/grid/node/config/DriverServiceSessionFactory.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,10 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
131131
attributeMap.put(AttributeKey.LOGGER_CLASS.getKey(), this.getClass().getName());
132132

133133
DriverService service = builder.build();
134-
if (service.getExecutable() == null) {
135-
Result result = DriverFinder.getPath(service, capabilities);
136-
service.setExecutable(result.getDriverPath());
137-
if (result.getBrowserPath() != null && !result.getBrowserPath().isEmpty()) {
138-
capabilities = setBrowserBinary(capabilities, result.getBrowserPath());
139-
}
134+
Result driverResult = DriverFinder.getPath(service, capabilities);
135+
service.setExecutable(driverResult.getDriverPath());
136+
if (driverResult.getBrowserPath() != null && !driverResult.getBrowserPath().isEmpty()) {
137+
capabilities = setBrowserBinary(capabilities, driverResult.getBrowserPath());
140138
}
141139

142140
Optional<Platform> platformName = Optional.ofNullable(capabilities.getPlatformName());

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.openqa.selenium.Capabilities;
2222
import org.openqa.selenium.Platform;
2323
import org.openqa.selenium.WebDriverException;
24+
import org.openqa.selenium.manager.SeleniumManagerOutput.Result;
2425
import org.openqa.selenium.remote.FileDetector;
2526
import org.openqa.selenium.remote.RemoteWebDriver;
2627
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
@@ -124,10 +125,8 @@ public InternetExplorerDriver(
124125
if (service == null) {
125126
service = InternetExplorerDriverService.createDefaultService();
126127
}
127-
if (service.getExecutable() == null) {
128-
String path = DriverFinder.getPath(service, options).getDriverPath();
129-
service.setExecutable(path);
130-
}
128+
Result result = DriverFinder.getPath(service, options);
129+
service.setExecutable(result.getDriverPath());
131130
if (clientConfig == null) {
132131
clientConfig = ClientConfig.defaultConfig();
133132
}

java/src/org/openqa/selenium/manager/SeleniumManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ private SeleniumManager() {
9797
}
9898
}
9999
}));
100+
} else {
101+
LOG.fine(String.format("Selenium Manager set by env 'SE_MANAGER_PATH': %s", managerPath));
100102
}
101103
}
102104

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.openqa.selenium.remote.service;
1919

2020
import java.io.File;
21+
import java.util.logging.Logger;
2122
import org.openqa.selenium.Capabilities;
2223
import org.openqa.selenium.WebDriverException;
2324
import org.openqa.selenium.internal.Require;
@@ -27,21 +28,35 @@
2728

2829
public class DriverFinder {
2930

31+
private static final Logger LOG = Logger.getLogger(DriverFinder.class.getName());
32+
3033
public static Result getPath(DriverService service, Capabilities options) {
3134
return getPath(service, options, false);
3235
}
3336

3437
public static Result getPath(DriverService service, Capabilities options, boolean offline) {
3538
Require.nonNull("Browser options", options);
36-
Result result = new Result(System.getProperty(service.getDriverProperty()));
39+
Result result = new Result(service.getExecutable());
40+
if (result.getDriverPath() != null) {
41+
LOG.fine(
42+
String.format(
43+
"Skipping Selenium Manager, path to %s specified in Service class: %s",
44+
service.getDriverName(), result.getDriverPath()));
45+
}
3746

47+
result = new Result(System.getProperty(service.getDriverProperty()));
3848
if (result.getDriverPath() == null) {
3949
try {
4050
result = SeleniumManager.getInstance().getDriverPath(options, offline);
4151
} catch (RuntimeException e) {
4252
throw new WebDriverException(
4353
String.format("Unable to obtain: %s, error %s", options, e.getMessage()), e);
4454
}
55+
} else {
56+
LOG.fine(
57+
String.format(
58+
"Skipping Selenium Manager, path to %s found in system property: %s",
59+
service.getDriverName(), result.getDriverPath()));
4560
}
4661

4762
String message;
@@ -50,7 +65,7 @@ public static Result getPath(DriverService service, Capabilities options, boolea
5065
} else if (!new File(result.getDriverPath()).exists()) {
5166
message =
5267
String.format(
53-
"%s located at %s, but invalid", service.getDriverName(), result.getDriverPath());
68+
"%s at location %s, does not exist", service.getDriverName(), result.getDriverPath());
5469
} else if (!new File(result.getDriverPath()).canExecute()) {
5570
message =
5671
String.format(

0 commit comments

Comments
 (0)