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.

0 commit comments

Comments
 (0)