Skip to content

Commit 5374cf8

Browse files
committed
[java] Invoking Selenium Manager only with --browser
1 parent 9812791 commit 5374cf8

14 files changed

+50
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public boolean isSupportingBiDi() {
6565
@Override
6666
public boolean isAvailable() {
6767
try {
68-
DriverFinder.getPath(ChromeDriverService.createDefaultService());
68+
DriverFinder.getPath(ChromeDriverService.createDefaultService(), getCanonicalCapabilities());
6969
return true;
7070
} catch (IllegalStateException | WebDriverException e) {
7171
return false;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ public String getDriverProperty() {
146146
return CHROME_DRIVER_EXE_PROPERTY;
147147
}
148148

149+
@Override
150+
public Capabilities getDefaultDriverOptions() {
151+
return new ChromeOptions();
152+
}
153+
149154
/**
150155
* Configures and returns a new {@link ChromeDriverService} using the default configuration. In
151156
* this configuration, the service will use the ChromeDriver executable identified by

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public boolean isSupportingBiDi() {
6666
@Override
6767
public boolean isAvailable() {
6868
try {
69-
DriverFinder.getPath(EdgeDriverService.createDefaultService());
69+
DriverFinder.getPath(EdgeDriverService.createDefaultService(), getCanonicalCapabilities());
7070
return true;
7171
} catch (IllegalStateException | WebDriverException e) {
7272
return false;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ public String getDriverProperty() {
121121
return EDGE_DRIVER_EXE_PROPERTY;
122122
}
123123

124+
@Override
125+
public Capabilities getDefaultDriverOptions() {
126+
return new EdgeOptions();
127+
}
128+
124129
/**
125130
* Configures and returns a new {@link EdgeDriverService} using the default configuration. In
126131
* this configuration, the service will use the MSEdgeDriver executable identified by the

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public boolean isSupportingBiDi() {
7070
@Override
7171
public boolean isAvailable() {
7272
try {
73-
DriverFinder.getPath(GeckoDriverService.createDefaultService());
73+
DriverFinder.getPath(GeckoDriverService.createDefaultService(), getCanonicalCapabilities());
7474
return true;
7575
} catch (IllegalStateException | WebDriverException e) {
7676
return false;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ public String getDriverProperty() {
8080
return GECKO_DRIVER_EXE_PROPERTY;
8181
}
8282

83+
@Override
84+
public Capabilities getDefaultDriverOptions() {
85+
return new FirefoxOptions();
86+
}
87+
8388
/**
8489
* @param executable The GeckoDriver executable.
8590
* @param port Which port to start the GeckoDriver on.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public boolean isSupportingBiDi() {
6666
public boolean isAvailable() {
6767
try {
6868
if (Platform.getCurrent().is(Platform.WINDOWS)) {
69-
DriverFinder.getPath(InternetExplorerDriverService.createDefaultService());
69+
DriverFinder.getPath(InternetExplorerDriverService.createDefaultService(),
70+
getCanonicalCapabilities());
7071
return true;
7172
}
7273
return false;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ public String getDriverProperty() {
9797
return IE_DRIVER_EXE_PROPERTY;
9898
}
9999

100+
@Override
101+
public Capabilities getDefaultDriverOptions() {
102+
return new InternetExplorerOptions();
103+
}
104+
100105
/**
101106
* Configures and returns a new {@link InternetExplorerDriverService} using the default configuration. In
102107
* this configuration, the service will use the IEDriverServer executable identified by the

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ public class DriverFinder {
1212

1313
private static final Logger LOG = Logger.getLogger(DriverFinder.class.getName());
1414

15-
public static String getPath(DriverServiceInfo serviceInfo) {
16-
return getPath(serviceInfo, null);
17-
}
18-
1915
public static String getPath(DriverServiceInfo serviceInfo, Capabilities options) {
16+
Require.nonNull("Browser options", options);
2017
String defaultPath = new ExecutableFinder().find(serviceInfo.getDriverName());
2118
String exePath = System.getProperty(serviceInfo.getDriverProperty(), defaultPath);
2219

@@ -26,11 +23,7 @@ public static String getPath(DriverServiceInfo serviceInfo, Capabilities options
2623

2724
if (exePath == null) {
2825
try {
29-
if (options == null) {
30-
exePath = SeleniumManager.getInstance().getDriverPath(serviceInfo.getDriverName());
31-
} else {
32-
exePath = SeleniumManager.getInstance().getDriverPath(options);
33-
}
26+
exePath = SeleniumManager.getInstance().getDriverPath(options);
3427
} catch (Exception e) {
3528
LOG.warning(String.format("Unable to obtain %s using Selenium Manager: %s",
3629
serviceInfo.getDriverName(), e.getMessage()));

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.openqa.selenium.Beta;
2323
import org.openqa.selenium.Capabilities;
24+
import org.openqa.selenium.ImmutableCapabilities;
2425
import org.openqa.selenium.WebDriverException;
2526
import org.openqa.selenium.internal.Require;
2627
import org.openqa.selenium.net.PortProber;
@@ -141,6 +142,10 @@ protected URL getUrl(int port) throws IOException {
141142
return new URL(String.format("http://localhost:%d", port));
142143
}
143144

145+
protected Capabilities getDefaultDriverOptions() {
146+
return new ImmutableCapabilities();
147+
}
148+
144149
/**
145150
* @return The base URL for the managed driver server.
146151
*/
@@ -178,7 +183,10 @@ public void start() throws IOException {
178183
return;
179184
}
180185
if (this.executable == null) {
181-
this.executable = DriverFinder.getPath(this);
186+
if (getDefaultDriverOptions().getBrowserName().isEmpty()) {
187+
throw new WebDriverException("Driver executable is null and browser name is not set.");
188+
}
189+
this.executable = DriverFinder.getPath(this, getDefaultDriverOptions());
182190
}
183191
process = new CommandLine(this.executable, args.toArray(new String[]{}));
184192
process.setEnvironmentVariables(environment);
@@ -272,7 +280,7 @@ public void stop() {
272280
if (getOutputStream() instanceof FileOutputStream) {
273281
try {
274282
getOutputStream().close();
275-
} catch (IOException e) {
283+
} catch (IOException ignore) {
276284
}
277285
}
278286
} finally {

0 commit comments

Comments
 (0)