diff --git a/java/src/org/openqa/selenium/chrome/ChromeDriverInfo.java b/java/src/org/openqa/selenium/chrome/ChromeDriverInfo.java index 9c52064b73690..cab7efa03c2f6 100644 --- a/java/src/org/openqa/selenium/chrome/ChromeDriverInfo.java +++ b/java/src/org/openqa/selenium/chrome/ChromeDriverInfo.java @@ -84,7 +84,12 @@ public boolean isAvailable() { @Override public boolean isPresent() { - return ChromeDriverService.isPresent(); + try { + DriverFinder.getPath(ChromeDriverService.createDefaultService(), getCanonicalCapabilities(), true); + return true; + } catch (IllegalStateException | WebDriverException e) { + return false; + } } @Override diff --git a/java/src/org/openqa/selenium/chrome/ChromeDriverService.java b/java/src/org/openqa/selenium/chrome/ChromeDriverService.java index de87f3e787e1a..350f066f87cf4 100644 --- a/java/src/org/openqa/selenium/chrome/ChromeDriverService.java +++ b/java/src/org/openqa/selenium/chrome/ChromeDriverService.java @@ -183,16 +183,6 @@ public static ChromeDriverService createServiceWithConfig(ChromeOptions options) return new Builder().withLogLevel(level).build(); } - /** - * Checks if the ChromeDriver binary is already present. Grid uses this method to show the - * available browsers and drivers, hence its visibility. - * - * @return Whether the browser driver path was found. - */ - static boolean isPresent() { - return findExePath(CHROME_DRIVER_NAME, CHROME_DRIVER_EXE_PROPERTY) != null; - } - /** Builder used to configure new {@link ChromeDriverService} instances. */ @AutoService(DriverService.Builder.class) public static class Builder diff --git a/java/src/org/openqa/selenium/edge/EdgeDriverInfo.java b/java/src/org/openqa/selenium/edge/EdgeDriverInfo.java index 1de73cebfb807..c5d2394eadf76 100644 --- a/java/src/org/openqa/selenium/edge/EdgeDriverInfo.java +++ b/java/src/org/openqa/selenium/edge/EdgeDriverInfo.java @@ -87,12 +87,12 @@ public boolean isAvailable() { @Override public boolean isPresent() { - return EdgeDriverService.isPresent(); - } - - @Override - public int getMaximumSimultaneousSessions() { - return Runtime.getRuntime().availableProcessors(); + try { + DriverFinder.getPath(EdgeDriverService.createDefaultService(), getCanonicalCapabilities(), true); + return true; + } catch (IllegalStateException | WebDriverException e) { + return false; + } } @Override diff --git a/java/src/org/openqa/selenium/edge/EdgeDriverService.java b/java/src/org/openqa/selenium/edge/EdgeDriverService.java index feb51d8b7b758..83089731e12e9 100644 --- a/java/src/org/openqa/selenium/edge/EdgeDriverService.java +++ b/java/src/org/openqa/selenium/edge/EdgeDriverService.java @@ -133,16 +133,6 @@ public static EdgeDriverService createDefaultService() { return new Builder().build(); } - /** - * Checks if the MSEdgeDriver binary is already present. Grid uses this method to show the - * available browsers and drivers, hence its visibility. - * - * @return Whether the browser driver path was found. - */ - static boolean isPresent() { - return findExePath(EDGE_DRIVER_NAME, EDGE_DRIVER_EXE_PROPERTY) != null; - } - /** Builder used to configure new {@link EdgeDriverService} instances. */ @AutoService(DriverService.Builder.class) public static class Builder extends DriverService.Builder { diff --git a/java/src/org/openqa/selenium/firefox/GeckoDriverInfo.java b/java/src/org/openqa/selenium/firefox/GeckoDriverInfo.java index 1644f2ac0c6bb..4a13bef850a60 100644 --- a/java/src/org/openqa/selenium/firefox/GeckoDriverInfo.java +++ b/java/src/org/openqa/selenium/firefox/GeckoDriverInfo.java @@ -77,7 +77,12 @@ public boolean isAvailable() { @Override public boolean isPresent() { - return GeckoDriverService.isPresent(); + try { + DriverFinder.getPath(GeckoDriverService.createDefaultService(), getCanonicalCapabilities(), true); + return true; + } catch (IllegalStateException | WebDriverException e) { + return false; + } } @Override diff --git a/java/src/org/openqa/selenium/firefox/GeckoDriverService.java b/java/src/org/openqa/selenium/firefox/GeckoDriverService.java index 621ed6bf54211..6247d4c4b1357 100644 --- a/java/src/org/openqa/selenium/firefox/GeckoDriverService.java +++ b/java/src/org/openqa/selenium/firefox/GeckoDriverService.java @@ -141,16 +141,6 @@ public static GeckoDriverService createDefaultService() { return new Builder().build(); } - /** - * Checks if the GeckoDriver binary is already present. Grid uses this method to show the - * available browsers and drivers, hence its visibility. - * - * @return Whether the browser driver path was found. - */ - static boolean isPresent() { - return findExePath(GECKO_DRIVER_NAME, GECKO_DRIVER_EXE_PROPERTY) != null; - } - /** * @param caps Capabilities instance - this is not used * @return default GeckoDriverService diff --git a/java/src/org/openqa/selenium/grid/node/config/NodeOptions.java b/java/src/org/openqa/selenium/grid/node/config/NodeOptions.java index 377d1321421f5..2b488ab781a37 100644 --- a/java/src/org/openqa/selenium/grid/node/config/NodeOptions.java +++ b/java/src/org/openqa/selenium/grid/node/config/NodeOptions.java @@ -59,7 +59,6 @@ import org.openqa.selenium.grid.node.SessionFactory; import org.openqa.selenium.internal.Require; import org.openqa.selenium.json.Json; -import org.openqa.selenium.json.JsonInput; import org.openqa.selenium.json.JsonOutput; import org.openqa.selenium.net.NetworkUtils; import org.openqa.selenium.net.Urls; @@ -569,18 +568,15 @@ private Map> discoverDrivers( .sorted(Comparator.comparing(info -> info.getDisplayName().toLowerCase())) .collect(Collectors.toList()); - LOG.log(Level.INFO, "Driver(s) already present on the host: {0}", infos.size()); - if (config.getBool(NODE_SECTION, "selenium-manager").orElse(DEFAULT_USE_SELENIUM_MANAGER)) { List present = infos.stream().map(WebDriverInfo::getDisplayName).collect(Collectors.toList()); List driversSM = StreamSupport.stream(ServiceLoader.load(WebDriverInfo.class).spliterator(), false) - .filter(WebDriverInfo::isAvailable) .filter(info -> !present.contains(info.getDisplayName())) + .filter(WebDriverInfo::isAvailable) .sorted(Comparator.comparing(info -> info.getDisplayName().toLowerCase())) .collect(Collectors.toList()); - LOG.log(Level.INFO, "Driver(s) available through Selenium Manager: {0}", driversSM.size()); infos.addAll(driversSM); } @@ -715,11 +711,10 @@ private void report(Map.Entry> entry) LOG.info( String.format( - "Adding %s for %s %d times (%s)", + "Adding %s for %s %d times", entry.getKey().getDisplayName(), caps.toString().replaceAll("\\s+", " "), - entry.getValue().size(), - entry.getKey().isPresent() ? "Host" : "SM")); + entry.getValue().size())); } private String unquote(String input) { diff --git a/java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java b/java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java index e60b57e4f0112..9e5f4345b79c7 100644 --- a/java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java +++ b/java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java @@ -144,7 +144,7 @@ public Either apply(CreateSessionRequest sess new SessionNotCreatedException( "New session request capabilities do not " + "match the stereotype.")); } - + capabilities = capabilities.merge(stereotype); LOG.info("Starting session for " + capabilities); try (Span span = tracer.getCurrentContext().createSpan("relay_session_factory.apply")) { diff --git a/java/src/org/openqa/selenium/ie/InternetExplorerDriverInfo.java b/java/src/org/openqa/selenium/ie/InternetExplorerDriverInfo.java index d2ebb12bb2617..3a308ade097be 100644 --- a/java/src/org/openqa/selenium/ie/InternetExplorerDriverInfo.java +++ b/java/src/org/openqa/selenium/ie/InternetExplorerDriverInfo.java @@ -75,8 +75,16 @@ public boolean isAvailable() { @Override public boolean isPresent() { - return InternetExplorerDriverService.isPresent(); - } + try { + if (Platform.getCurrent().is(Platform.WINDOWS)) { + DriverFinder.getPath( + InternetExplorerDriverService.createDefaultService(), getCanonicalCapabilities(), true); + return true; + } + return false; + } catch (IllegalStateException | WebDriverException e) { + return false; + } } @Override public int getMaximumSimultaneousSessions() { diff --git a/java/src/org/openqa/selenium/ie/InternetExplorerDriverService.java b/java/src/org/openqa/selenium/ie/InternetExplorerDriverService.java index d4b5e38a74c05..db4e7eab7d4b9 100644 --- a/java/src/org/openqa/selenium/ie/InternetExplorerDriverService.java +++ b/java/src/org/openqa/selenium/ie/InternetExplorerDriverService.java @@ -114,16 +114,6 @@ public static InternetExplorerDriverService createDefaultService() { return new Builder().build(); } - /** - * Checks if the IEDriverServer binary is available. Grid uses this method to show the available - * browsers and drivers, hence its visibility. - * - * @return Whether the browser driver path was found. - */ - static boolean isPresent() { - return findExePath(IE_DRIVER_NAME, IE_DRIVER_EXE_PROPERTY) != null; - } - /** Builder used to configure new {@link InternetExplorerDriverService} instances. */ @AutoService(DriverService.Builder.class) public static class Builder diff --git a/java/src/org/openqa/selenium/manager/SeleniumManager.java b/java/src/org/openqa/selenium/manager/SeleniumManager.java index a4654d841e494..8e0bd2377608e 100644 --- a/java/src/org/openqa/selenium/manager/SeleniumManager.java +++ b/java/src/org/openqa/selenium/manager/SeleniumManager.java @@ -223,7 +223,7 @@ private String getBrowserBinary(Capabilities options) { * @param options Browser Options instance. * @return the location of the driver. */ - public String getDriverPath(Capabilities options) { + public String getDriverPath(Capabilities options, boolean offline) { LOG.fine("Applicable driver not found; attempting to install with Selenium Manager (Beta)"); File binaryFile = getBinary(); if (binaryFile == null) { @@ -251,6 +251,10 @@ public String getDriverPath(Capabilities options) { commandList.add("--debug"); } + if (offline) { + commandList.add("--offline"); + } + Proxy proxy = (Proxy) options.getCapability("proxy"); if (proxy != null) { if (proxy.getSslProxy() != null) { diff --git a/java/src/org/openqa/selenium/remote/service/DriverFinder.java b/java/src/org/openqa/selenium/remote/service/DriverFinder.java index 9bd5b8a62f020..c4c2fac3e5702 100644 --- a/java/src/org/openqa/selenium/remote/service/DriverFinder.java +++ b/java/src/org/openqa/selenium/remote/service/DriverFinder.java @@ -1,7 +1,6 @@ package org.openqa.selenium.remote.service; import java.io.File; -import java.util.logging.Logger; import org.openqa.selenium.Capabilities; import org.openqa.selenium.internal.Require; import org.openqa.selenium.manager.SeleniumManager; @@ -10,18 +9,22 @@ public class DriverFinder { public static String getPath(DriverService service, Capabilities options) { + return getPath(service, options, false); + } + + public static String getPath(DriverService service, Capabilities options, boolean offline) { Require.nonNull("Browser options", options); String exePath = System.getProperty(service.getDriverProperty()); if (exePath == null) { try { - exePath = SeleniumManager.getInstance().getDriverPath(options); + exePath = SeleniumManager.getInstance().getDriverPath(options, offline); } catch (Exception e) { throw new NoSuchDriverException(String.format("Unable to obtain: %s", options), e); } } - String message = ""; + String message; if (exePath == null) { message = String.format("Unable to locate or obtain %s", service.getDriverName()); } else if (!new File(exePath).exists()) { diff --git a/java/src/org/openqa/selenium/remote/service/DriverService.java b/java/src/org/openqa/selenium/remote/service/DriverService.java index 776f673759cf0..7e99340519850 100644 --- a/java/src/org/openqa/selenium/remote/service/DriverService.java +++ b/java/src/org/openqa/selenium/remote/service/DriverService.java @@ -131,11 +131,6 @@ public void setExecutable(String executable) { this.executable = executable; } - protected static String findExePath(String exeName, String exeProperty) { - String defaultPath = new ExecutableFinder().find(exeName); - return System.getProperty(exeProperty, defaultPath); - } - protected List getArgs() { return args; } @@ -465,9 +460,6 @@ protected OutputStream getLogOutput(String logProperty) { } if (logLocation == null) { - LOG.info( - "Driver logs no longer sent to console by default; " - + "https://www.selenium.dev/documentation/webdriver/drivers/service/#setting-log-output"); return ByteStreams.nullOutputStream(); } diff --git a/java/src/org/openqa/selenium/safari/SafariDriverInfo.java b/java/src/org/openqa/selenium/safari/SafariDriverInfo.java index 6342d05f1d7f6..93fa3c6847cf5 100644 --- a/java/src/org/openqa/selenium/safari/SafariDriverInfo.java +++ b/java/src/org/openqa/selenium/safari/SafariDriverInfo.java @@ -77,7 +77,12 @@ public boolean isAvailable() { @Override public boolean isPresent() { - return SafariDriverService.isPresent(); + try { + DriverFinder.getPath(SafariDriverService.createDefaultService(), getCanonicalCapabilities(), true); + return true; + } catch (IllegalStateException | WebDriverException e) { + return false; + } } @Override diff --git a/java/src/org/openqa/selenium/safari/SafariDriverService.java b/java/src/org/openqa/selenium/safari/SafariDriverService.java index 6b00c6eabfefd..ab20dfe8c0c93 100644 --- a/java/src/org/openqa/selenium/safari/SafariDriverService.java +++ b/java/src/org/openqa/selenium/safari/SafariDriverService.java @@ -118,17 +118,6 @@ public static SafariDriverService createDefaultService() { return new Builder().build(); } - /** - * Checks if the SafariDriver binary is available. Grid uses this method to show the available - * browsers and drivers, hence its visibility. - * - * @return Whether the browser driver path was found. - */ - static boolean isPresent() { - return findExePath(SAFARI_DRIVER_EXECUTABLE.getAbsolutePath(), SAFARI_DRIVER_EXE_PROPERTY) - != null; - } - @Override protected void waitUntilAvailable() { try { diff --git a/java/src/org/openqa/selenium/safari/SafariTechPreviewDriverInfo.java b/java/src/org/openqa/selenium/safari/SafariTechPreviewDriverInfo.java index d5743271e6388..4c6b0e2f1f91b 100644 --- a/java/src/org/openqa/selenium/safari/SafariTechPreviewDriverInfo.java +++ b/java/src/org/openqa/selenium/safari/SafariTechPreviewDriverInfo.java @@ -79,7 +79,13 @@ public boolean isAvailable() { @Override public boolean isPresent() { - return SafariTechPreviewDriverService.isPresent(); + try { + DriverFinder.getPath( + SafariTechPreviewDriverService.createDefaultService(), getCanonicalCapabilities(), true); + return true; + } catch (IllegalStateException | WebDriverException e) { + return false; + } } @Override diff --git a/java/src/org/openqa/selenium/safari/SafariTechPreviewDriverService.java b/java/src/org/openqa/selenium/safari/SafariTechPreviewDriverService.java index 3f1993139d4db..c1a9b04fec7fc 100644 --- a/java/src/org/openqa/selenium/safari/SafariTechPreviewDriverService.java +++ b/java/src/org/openqa/selenium/safari/SafariTechPreviewDriverService.java @@ -121,17 +121,6 @@ public static SafariTechPreviewDriverService createDefaultService() { return new Builder().build(); } - /** - * Checks if the SafariDriver driver binary is available. Grid uses this method to show the - * available browsers and drivers, hence its visibility. - * - * @return Whether the browser driver path was found. - */ - static boolean isPresent() { - return findExePath(TP_SAFARI_DRIVER_EXECUTABLE.getAbsolutePath(), TP_SAFARI_DRIVER_EXE_PROPERTY) - != null; - } - @Override protected void waitUntilAvailable() { try {