Skip to content

Commit 0013140

Browse files
committed
[grid] Using SM to find drivers on PATH
Grid portion of #11356
1 parent 44d202c commit 0013140

17 files changed

+56
-95
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,12 @@ public boolean isAvailable() {
8484

8585
@Override
8686
public boolean isPresent() {
87-
return ChromeDriverService.isPresent();
87+
try {
88+
DriverFinder.getPath(ChromeDriverService.createDefaultService(), getCanonicalCapabilities(), true);
89+
return true;
90+
} catch (IllegalStateException | WebDriverException e) {
91+
return false;
92+
}
8893
}
8994

9095
@Override

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,6 @@ public static ChromeDriverService createServiceWithConfig(ChromeOptions options)
183183
return new Builder().withLogLevel(level).build();
184184
}
185185

186-
/**
187-
* Checks if the ChromeDriver binary is already present. Grid uses this method to show the
188-
* available browsers and drivers, hence its visibility.
189-
*
190-
* @return Whether the browser driver path was found.
191-
*/
192-
static boolean isPresent() {
193-
return findExePath(CHROME_DRIVER_NAME, CHROME_DRIVER_EXE_PROPERTY) != null;
194-
}
195-
196186
/** Builder used to configure new {@link ChromeDriverService} instances. */
197187
@AutoService(DriverService.Builder.class)
198188
public static class Builder

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ public boolean isAvailable() {
8787

8888
@Override
8989
public boolean isPresent() {
90-
return EdgeDriverService.isPresent();
91-
}
92-
93-
@Override
94-
public int getMaximumSimultaneousSessions() {
95-
return Runtime.getRuntime().availableProcessors();
90+
try {
91+
DriverFinder.getPath(EdgeDriverService.createDefaultService(), getCanonicalCapabilities(), true);
92+
return true;
93+
} catch (IllegalStateException | WebDriverException e) {
94+
return false;
95+
}
9696
}
9797

9898
@Override

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,6 @@ public static EdgeDriverService createDefaultService() {
133133
return new Builder().build();
134134
}
135135

136-
/**
137-
* Checks if the MSEdgeDriver binary is already present. Grid uses this method to show the
138-
* available browsers and drivers, hence its visibility.
139-
*
140-
* @return Whether the browser driver path was found.
141-
*/
142-
static boolean isPresent() {
143-
return findExePath(EDGE_DRIVER_NAME, EDGE_DRIVER_EXE_PROPERTY) != null;
144-
}
145-
146136
/** Builder used to configure new {@link EdgeDriverService} instances. */
147137
@AutoService(DriverService.Builder.class)
148138
public static class Builder extends DriverService.Builder<EdgeDriverService, Builder> {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ public boolean isAvailable() {
7777

7878
@Override
7979
public boolean isPresent() {
80-
return GeckoDriverService.isPresent();
80+
try {
81+
DriverFinder.getPath(GeckoDriverService.createDefaultService(), getCanonicalCapabilities(), true);
82+
return true;
83+
} catch (IllegalStateException | WebDriverException e) {
84+
return false;
85+
}
8186
}
8287

8388
@Override

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,6 @@ public static GeckoDriverService createDefaultService() {
141141
return new Builder().build();
142142
}
143143

144-
/**
145-
* Checks if the GeckoDriver binary is already present. Grid uses this method to show the
146-
* available browsers and drivers, hence its visibility.
147-
*
148-
* @return Whether the browser driver path was found.
149-
*/
150-
static boolean isPresent() {
151-
return findExePath(GECKO_DRIVER_NAME, GECKO_DRIVER_EXE_PROPERTY) != null;
152-
}
153-
154144
/**
155145
* @param caps Capabilities instance - this is not used
156146
* @return default GeckoDriverService

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
import org.openqa.selenium.grid.node.SessionFactory;
6060
import org.openqa.selenium.internal.Require;
6161
import org.openqa.selenium.json.Json;
62-
import org.openqa.selenium.json.JsonInput;
6362
import org.openqa.selenium.json.JsonOutput;
6463
import org.openqa.selenium.net.NetworkUtils;
6564
import org.openqa.selenium.net.Urls;
@@ -569,18 +568,15 @@ private Map<WebDriverInfo, Collection<SessionFactory>> discoverDrivers(
569568
.sorted(Comparator.comparing(info -> info.getDisplayName().toLowerCase()))
570569
.collect(Collectors.toList());
571570

572-
LOG.log(Level.INFO, "Driver(s) already present on the host: {0}", infos.size());
573-
574571
if (config.getBool(NODE_SECTION, "selenium-manager").orElse(DEFAULT_USE_SELENIUM_MANAGER)) {
575572
List<String> present =
576573
infos.stream().map(WebDriverInfo::getDisplayName).collect(Collectors.toList());
577574
List<WebDriverInfo> driversSM =
578575
StreamSupport.stream(ServiceLoader.load(WebDriverInfo.class).spliterator(), false)
579-
.filter(WebDriverInfo::isAvailable)
580576
.filter(info -> !present.contains(info.getDisplayName()))
577+
.filter(WebDriverInfo::isAvailable)
581578
.sorted(Comparator.comparing(info -> info.getDisplayName().toLowerCase()))
582579
.collect(Collectors.toList());
583-
LOG.log(Level.INFO, "Driver(s) available through Selenium Manager: {0}", driversSM.size());
584580
infos.addAll(driversSM);
585581
}
586582

@@ -715,11 +711,10 @@ private void report(Map.Entry<WebDriverInfo, Collection<SessionFactory>> entry)
715711

716712
LOG.info(
717713
String.format(
718-
"Adding %s for %s %d times (%s)",
714+
"Adding %s for %s %d times",
719715
entry.getKey().getDisplayName(),
720716
caps.toString().replaceAll("\\s+", " "),
721-
entry.getValue().size(),
722-
entry.getKey().isPresent() ? "Host" : "SM"));
717+
entry.getValue().size()));
723718
}
724719

725720
private String unquote(String input) {

java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public Either<WebDriverException, ActiveSession> apply(CreateSessionRequest sess
144144
new SessionNotCreatedException(
145145
"New session request capabilities do not " + "match the stereotype."));
146146
}
147-
147+
capabilities = capabilities.merge(stereotype);
148148
LOG.info("Starting session for " + capabilities);
149149

150150
try (Span span = tracer.getCurrentContext().createSpan("relay_session_factory.apply")) {

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,16 @@ public boolean isAvailable() {
7575

7676
@Override
7777
public boolean isPresent() {
78-
return InternetExplorerDriverService.isPresent();
79-
}
78+
try {
79+
if (Platform.getCurrent().is(Platform.WINDOWS)) {
80+
DriverFinder.getPath(
81+
InternetExplorerDriverService.createDefaultService(), getCanonicalCapabilities(), true);
82+
return true;
83+
}
84+
return false;
85+
} catch (IllegalStateException | WebDriverException e) {
86+
return false;
87+
} }
8088

8189
@Override
8290
public int getMaximumSimultaneousSessions() {

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,6 @@ public static InternetExplorerDriverService createDefaultService() {
114114
return new Builder().build();
115115
}
116116

117-
/**
118-
* Checks if the IEDriverServer binary is available. Grid uses this method to show the available
119-
* browsers and drivers, hence its visibility.
120-
*
121-
* @return Whether the browser driver path was found.
122-
*/
123-
static boolean isPresent() {
124-
return findExePath(IE_DRIVER_NAME, IE_DRIVER_EXE_PROPERTY) != null;
125-
}
126-
127117
/** Builder used to configure new {@link InternetExplorerDriverService} instances. */
128118
@AutoService(DriverService.Builder.class)
129119
public static class Builder

0 commit comments

Comments
 (0)