Skip to content

Commit 4ecc103

Browse files
titusfortnerdiemol
andauthored
[java] Selenium Manager generates output from argument list (#13385)
* [java] rename driver finder and selenium manager methods to getResult * [java] Selenium Manager generates output from argument list instead of capabilities instance * [java] allow driver finder to store state instead of static * [java] rename method to getBinaryPaths * [java] rename method again * [java] false and true are different * a getter method should have a return value --------- Co-authored-by: Diego Molina <[email protected]>
1 parent 25fd49a commit 4ecc103

26 files changed

+370
-317
lines changed

java/src/org/openqa/selenium/PersistentCapabilities.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ private PersistentCapabilities(Capabilities previousValues, Capabilities newValu
5050

5151
public PersistentCapabilities setCapability(String name, Object value) {
5252
Require.nonNull("Name", name);
53-
Require.nonNull("Value", value);
5453

5554
return new PersistentCapabilities(this, new ImmutableCapabilities(name, value));
5655
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.openqa.selenium.chromium.ChromiumDriver;
2727
import org.openqa.selenium.chromium.ChromiumDriverCommandExecutor;
2828
import org.openqa.selenium.internal.Require;
29-
import org.openqa.selenium.manager.SeleniumManagerOutput.Result;
3029
import org.openqa.selenium.remote.CommandInfo;
3130
import org.openqa.selenium.remote.RemoteWebDriver;
3231
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
@@ -96,10 +95,11 @@ private static ChromeDriverCommandExecutor generateExecutor(
9695
Require.nonNull("Driver service", service);
9796
Require.nonNull("Driver options", options);
9897
Require.nonNull("Driver clientConfig", clientConfig);
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());
98+
DriverFinder finder = new DriverFinder(service, options);
99+
service.setExecutable(finder.getDriverPath());
100+
if (finder.hasBrowserPath()) {
101+
options.setBinary(finder.getBrowserPath());
102+
options.setCapability("browserVersion", (Object) null);
103103
}
104104
return new ChromeDriverCommandExecutor(service, clientConfig);
105105
}

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

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@
2121

2222
import com.google.auto.service.AutoService;
2323
import java.util.Optional;
24-
import java.util.logging.Level;
2524
import java.util.logging.Logger;
2625
import org.openqa.selenium.Capabilities;
2726
import org.openqa.selenium.ImmutableCapabilities;
2827
import org.openqa.selenium.SessionNotCreatedException;
2928
import org.openqa.selenium.WebDriver;
30-
import org.openqa.selenium.WebDriverException;
3129
import org.openqa.selenium.WebDriverInfo;
3230
import org.openqa.selenium.chromium.ChromiumDriverInfo;
3331
import org.openqa.selenium.remote.CapabilityType;
34-
import org.openqa.selenium.remote.NoSuchDriverException;
3532
import org.openqa.selenium.remote.service.DriverFinder;
3633

3734
@AutoService(WebDriverInfo.class)
@@ -65,29 +62,14 @@ public boolean isSupportingBiDi() {
6562

6663
@Override
6764
public boolean isAvailable() {
68-
try {
69-
DriverFinder.getPath(ChromeDriverService.createDefaultService(), getCanonicalCapabilities());
70-
return true;
71-
} catch (NoSuchDriverException e) {
72-
return false;
73-
} catch (IllegalStateException | WebDriverException e) {
74-
LOG.log(Level.WARNING, "failed to discover driver path", e);
75-
return false;
76-
}
65+
return new DriverFinder(ChromeDriverService.createDefaultService(), getCanonicalCapabilities())
66+
.isAvailable();
7767
}
7868

7969
@Override
8070
public boolean isPresent() {
81-
try {
82-
DriverFinder.getPath(
83-
ChromeDriverService.createDefaultService(), getCanonicalCapabilities(), true);
84-
return true;
85-
} catch (NoSuchDriverException e) {
86-
return false;
87-
} catch (IllegalStateException | WebDriverException e) {
88-
LOG.log(Level.WARNING, "failed to discover driver path", e);
89-
return false;
90-
}
71+
return new DriverFinder(ChromeDriverService.createDefaultService(), getCanonicalCapabilities())
72+
.isPresent();
9173
}
9274

9375
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public Capabilities getDefaultDriverOptions() {
128128
/**
129129
* Configures and returns a new {@link ChromeDriverService} using the default configuration. In
130130
* this configuration, the service will use the ChromeDriver executable identified by {@link
131-
* org.openqa.selenium.remote.service.DriverFinder#getPath(DriverService, Capabilities)}. Each
131+
* org.openqa.selenium.remote.service.DriverFinder#getResult(DriverService, Capabilities)}. Each
132132
* service created by this method will be configured to use a free port on the current system.
133133
*
134134
* @return A new ChromeDriverService using the default configuration.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.openqa.selenium.chromium.ChromiumDriver;
2525
import org.openqa.selenium.chromium.ChromiumDriverCommandExecutor;
2626
import org.openqa.selenium.internal.Require;
27-
import org.openqa.selenium.manager.SeleniumManagerOutput.Result;
2827
import org.openqa.selenium.remote.CommandInfo;
2928
import org.openqa.selenium.remote.RemoteWebDriver;
3029
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
@@ -68,10 +67,11 @@ private static EdgeDriverCommandExecutor generateExecutor(
6867
Require.nonNull("Driver service", service);
6968
Require.nonNull("Driver options", options);
7069
Require.nonNull("Driver clientConfig", clientConfig);
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());
70+
DriverFinder finder = new DriverFinder(service, options);
71+
service.setExecutable(finder.getDriverPath());
72+
if (finder.hasBrowserPath()) {
73+
options.setBinary(finder.getBrowserPath());
74+
options.setCapability("browserVersion", (Object) null);
7575
}
7676
return new EdgeDriverCommandExecutor(service, clientConfig);
7777
}

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

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@
2121

2222
import com.google.auto.service.AutoService;
2323
import java.util.Optional;
24-
import java.util.logging.Level;
2524
import java.util.logging.Logger;
2625
import org.openqa.selenium.Capabilities;
2726
import org.openqa.selenium.ImmutableCapabilities;
2827
import org.openqa.selenium.SessionNotCreatedException;
2928
import org.openqa.selenium.WebDriver;
30-
import org.openqa.selenium.WebDriverException;
3129
import org.openqa.selenium.WebDriverInfo;
3230
import org.openqa.selenium.chromium.ChromiumDriverInfo;
3331
import org.openqa.selenium.remote.CapabilityType;
34-
import org.openqa.selenium.remote.NoSuchDriverException;
3532
import org.openqa.selenium.remote.service.DriverFinder;
3633

3734
@AutoService(WebDriverInfo.class)
@@ -68,29 +65,14 @@ public boolean isSupportingBiDi() {
6865

6966
@Override
7067
public boolean isAvailable() {
71-
try {
72-
DriverFinder.getPath(EdgeDriverService.createDefaultService(), getCanonicalCapabilities());
73-
return true;
74-
} catch (NoSuchDriverException e) {
75-
return false;
76-
} catch (IllegalStateException | WebDriverException e) {
77-
LOG.log(Level.WARNING, "failed to discover driver path", e);
78-
return false;
79-
}
68+
return new DriverFinder(EdgeDriverService.createDefaultService(), getCanonicalCapabilities())
69+
.isAvailable();
8070
}
8171

8272
@Override
8373
public boolean isPresent() {
84-
try {
85-
DriverFinder.getPath(
86-
EdgeDriverService.createDefaultService(), getCanonicalCapabilities(), true);
87-
return true;
88-
} catch (NoSuchDriverException e) {
89-
return false;
90-
} catch (IllegalStateException | WebDriverException e) {
91-
LOG.log(Level.WARNING, "failed to discover driver path", e);
92-
return false;
93-
}
74+
return new DriverFinder(EdgeDriverService.createDefaultService(), getCanonicalCapabilities())
75+
.isPresent();
9476
}
9577

9678
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public Capabilities getDefaultDriverOptions() {
117117
/**
118118
* Configures and returns a new {@link EdgeDriverService} using the default configuration. In this
119119
* configuration, the service will use the MSEdgeDriver executable identified by the {@link
120-
* org.openqa.selenium.remote.service.DriverFinder#getPath(DriverService, Capabilities)}. Each
120+
* org.openqa.selenium.remote.service.DriverFinder#getResult(DriverService, Capabilities)}. Each
121121
* service created by this method will be configured to use a free port on the current system.
122122
*
123123
* @return A new EdgeDriverService using the default configuration.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import org.openqa.selenium.html5.SessionStorage;
5252
import org.openqa.selenium.html5.WebStorage;
5353
import org.openqa.selenium.internal.Require;
54-
import org.openqa.selenium.manager.SeleniumManagerOutput.Result;
5554
import org.openqa.selenium.remote.CommandInfo;
5655
import org.openqa.selenium.remote.FileDetector;
5756
import org.openqa.selenium.remote.RemoteWebDriver;
@@ -138,10 +137,11 @@ private static FirefoxDriverCommandExecutor generateExecutor(
138137
Require.nonNull("Driver service", service);
139138
Require.nonNull("Driver options", options);
140139
Require.nonNull("Driver clientConfig", clientConfig);
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());
140+
DriverFinder finder = new DriverFinder(service, options);
141+
service.setExecutable(finder.getDriverPath());
142+
if (finder.hasBrowserPath()) {
143+
options.setBinary(finder.getBrowserPath());
144+
options.setCapability("browserVersion", (Object) null);
145145
}
146146
return new FirefoxDriverCommandExecutor(service, clientConfig);
147147
}

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

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@
2222

2323
import com.google.auto.service.AutoService;
2424
import java.util.Optional;
25-
import java.util.logging.Level;
2625
import java.util.logging.Logger;
2726
import org.openqa.selenium.Capabilities;
2827
import org.openqa.selenium.ImmutableCapabilities;
2928
import org.openqa.selenium.SessionNotCreatedException;
3029
import org.openqa.selenium.WebDriver;
31-
import org.openqa.selenium.WebDriverException;
3230
import org.openqa.selenium.WebDriverInfo;
33-
import org.openqa.selenium.remote.NoSuchDriverException;
3431
import org.openqa.selenium.remote.service.DriverFinder;
3532

3633
@AutoService(WebDriverInfo.class)
@@ -68,29 +65,14 @@ public boolean isSupportingBiDi() {
6865

6966
@Override
7067
public boolean isAvailable() {
71-
try {
72-
DriverFinder.getPath(GeckoDriverService.createDefaultService(), getCanonicalCapabilities());
73-
return true;
74-
} catch (NoSuchDriverException e) {
75-
return false;
76-
} catch (IllegalStateException | WebDriverException e) {
77-
LOG.log(Level.WARNING, "failed to discover driver path", e);
78-
return false;
79-
}
68+
return new DriverFinder(GeckoDriverService.createDefaultService(), getCanonicalCapabilities())
69+
.isAvailable();
8070
}
8171

8272
@Override
8373
public boolean isPresent() {
84-
try {
85-
DriverFinder.getPath(
86-
GeckoDriverService.createDefaultService(), getCanonicalCapabilities(), true);
87-
return true;
88-
} catch (NoSuchDriverException e) {
89-
return false;
90-
} catch (IllegalStateException | WebDriverException e) {
91-
LOG.log(Level.WARNING, "failed to discover driver path", e);
92-
return false;
93-
}
74+
return new DriverFinder(GeckoDriverService.createDefaultService(), getCanonicalCapabilities())
75+
.isPresent();
9476
}
9577

9678
@Override

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public Capabilities getDefaultDriverOptions() {
110110
/**
111111
* Configures and returns a new {@link GeckoDriverService} using the default configuration. In
112112
* this configuration, the service will use the GeckoDriver executable identified by the {@link
113-
* org.openqa.selenium.remote.service.DriverFinder#getPath(DriverService, Capabilities)}. Each
113+
* org.openqa.selenium.remote.service.DriverFinder#getResult(DriverService, Capabilities)}. Each
114114
* service created by this method will be configured to use a free port on the current system.
115115
*
116116
* @return A new GeckoDriverService using the default configuration.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import org.openqa.selenium.grid.node.SessionFactory;
5050
import org.openqa.selenium.internal.Either;
5151
import org.openqa.selenium.internal.Require;
52-
import org.openqa.selenium.manager.SeleniumManagerOutput.Result;
5352
import org.openqa.selenium.net.HostIdentifier;
5453
import org.openqa.selenium.net.NetworkUtils;
5554
import org.openqa.selenium.remote.Command;
@@ -130,10 +129,10 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
130129
attributeMap.put(AttributeKey.LOGGER_CLASS.getKey(), this.getClass().getName());
131130

132131
DriverService service = builder.build();
133-
Result driverResult = DriverFinder.getPath(service, capabilities);
134-
service.setExecutable(driverResult.getDriverPath());
135-
if (driverResult.getBrowserPath() != null && !driverResult.getBrowserPath().isEmpty()) {
136-
capabilities = setBrowserBinary(capabilities, driverResult.getBrowserPath());
132+
DriverFinder finder = new DriverFinder(service, capabilities);
133+
service.setExecutable(finder.getDriverPath());
134+
if (finder.hasBrowserPath()) {
135+
capabilities = setBrowserBinary(capabilities, finder.getBrowserPath());
137136
}
138137

139138
Optional<Platform> platformName = Optional.ofNullable(capabilities.getPlatformName());
@@ -327,7 +326,8 @@ private Capabilities setBrowserBinary(Capabilities options, String browserPath)
327326
(Map<String, Object>) options.getCapability(vendorOptionsCapability);
328327
vendorOptions.put("binary", browserPath);
329328
return new PersistentCapabilities(options)
330-
.setCapability(vendorOptionsCapability, vendorOptions);
329+
.setCapability(vendorOptionsCapability, vendorOptions)
330+
.setCapability("browserVersion", null);
331331
} catch (Exception e) {
332332
LOG.warning(
333333
String.format(

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
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;
2524
import org.openqa.selenium.remote.FileDetector;
2625
import org.openqa.selenium.remote.RemoteWebDriver;
2726
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
@@ -125,8 +124,7 @@ public InternetExplorerDriver(
125124
if (service == null) {
126125
service = InternetExplorerDriverService.createDefaultService();
127126
}
128-
Result result = DriverFinder.getPath(service, options);
129-
service.setExecutable(result.getDriverPath());
127+
service.setExecutable(new DriverFinder(service, options).getDriverPath());
130128
if (clientConfig == null) {
131129
clientConfig = ClientConfig.defaultConfig();
132130
}

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

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@
2222

2323
import com.google.auto.service.AutoService;
2424
import java.util.Optional;
25-
import java.util.logging.Level;
2625
import java.util.logging.Logger;
2726
import org.openqa.selenium.Capabilities;
2827
import org.openqa.selenium.ImmutableCapabilities;
2928
import org.openqa.selenium.Platform;
3029
import org.openqa.selenium.SessionNotCreatedException;
3130
import org.openqa.selenium.WebDriver;
32-
import org.openqa.selenium.WebDriverException;
3331
import org.openqa.selenium.WebDriverInfo;
34-
import org.openqa.selenium.remote.NoSuchDriverException;
3532
import org.openqa.selenium.remote.service.DriverFinder;
3633

3734
@AutoService(WebDriverInfo.class)
@@ -65,36 +62,18 @@ public boolean isSupportingBiDi() {
6562

6663
@Override
6764
public boolean isAvailable() {
68-
try {
69-
if (Platform.getCurrent().is(Platform.WINDOWS)) {
70-
DriverFinder.getPath(
71-
InternetExplorerDriverService.createDefaultService(), getCanonicalCapabilities());
72-
return true;
73-
}
74-
return false;
75-
} catch (NoSuchDriverException e) {
76-
return false;
77-
} catch (IllegalStateException | WebDriverException e) {
78-
LOG.log(Level.WARNING, "failed to discover driver path", e);
79-
return false;
80-
}
65+
return Platform.getCurrent().is(Platform.WINDOWS)
66+
&& new DriverFinder(
67+
InternetExplorerDriverService.createDefaultService(), getCanonicalCapabilities())
68+
.isAvailable();
8169
}
8270

8371
@Override
8472
public boolean isPresent() {
85-
try {
86-
if (Platform.getCurrent().is(Platform.WINDOWS)) {
87-
DriverFinder.getPath(
88-
InternetExplorerDriverService.createDefaultService(), getCanonicalCapabilities(), true);
89-
return true;
90-
}
91-
return false;
92-
} catch (NoSuchDriverException e) {
93-
return false;
94-
} catch (IllegalStateException | WebDriverException e) {
95-
LOG.log(Level.WARNING, "failed to discover driver path", e);
96-
return false;
97-
}
73+
return Platform.getCurrent().is(Platform.WINDOWS)
74+
&& new DriverFinder(
75+
InternetExplorerDriverService.createDefaultService(), getCanonicalCapabilities())
76+
.isPresent();
9877
}
9978

10079
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ public Capabilities getDefaultDriverOptions() {
104104
/**
105105
* Configures and returns a new {@link InternetExplorerDriverService} using the default
106106
* configuration. In this configuration, the service will use the IEDriverServer executable
107-
* identified by the {@link org.openqa.selenium.remote.service.DriverFinder#getPath(DriverService,
108-
* Capabilities)}. Each service created by this method will be configured to use a free port on
109-
* the current system.
107+
* identified by the {@link
108+
* org.openqa.selenium.remote.service.DriverFinder#getResult(DriverService, Capabilities)}. Each
109+
* service created by this method will be configured to use a free port on the current system.
110110
*
111111
* @return A new InternetExplorerDriverService using the default configuration.
112112
*/

0 commit comments

Comments
 (0)