Skip to content
Merged
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/chrome/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ java_export(
"//java/src/org/openqa/selenium/chromium",
"//java/src/org/openqa/selenium/json",
"//java/src/org/openqa/selenium/remote",
"//java/src/org/openqa/selenium/manager:manager",
artifact("com.google.guava:guava"),
],
)
13 changes: 12 additions & 1 deletion java/src/org/openqa/selenium/chrome/ChromeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
import org.openqa.selenium.remote.service.DriverFinder;
import org.openqa.selenium.remote.service.DriverService;

import java.util.Map;
Expand Down Expand Up @@ -79,11 +80,21 @@ public ChromeDriver(ChromeOptions options) {
* @param options The options required from ChromeDriver.
*/
public ChromeDriver(ChromeDriverService service, ChromeOptions options) {
super(new ChromeDriverCommandExecutor(service), Require.nonNull("Driver options", options), ChromeOptions.CAPABILITY);
super(generateExecutor(service, options), options, ChromeOptions.CAPABILITY);
casting = new AddHasCasting().getImplementation(getCapabilities(), getExecuteMethod());
cdp = new AddHasCdp().getImplementation(getCapabilities(), getExecuteMethod());
}

private static ChromeDriverCommandExecutor generateExecutor(ChromeDriverService service, ChromeOptions options) {
Require.nonNull("Driver service", service);
Require.nonNull("Driver options", options);
if (service.getExecutable() == null) {
String path = DriverFinder.getPath(service, options);
service.setExecutable(path);
}
return new ChromeDriverCommandExecutor(service);
}

@Beta
public static RemoteWebDriverBuilder builder() {
return RemoteWebDriver.builder().oneOf(new ChromeOptions());
Expand Down
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/chrome/ChromeDriverInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.openqa.selenium.WebDriverInfo;
import org.openqa.selenium.chromium.ChromiumDriverInfo;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.service.DriverFinder;

import java.util.Optional;

Expand Down Expand Up @@ -64,7 +65,7 @@ public boolean isSupportingBiDi() {
@Override
public boolean isAvailable() {
try {
ChromeDriverService.createDefaultService();
DriverFinder.getPath(ChromeDriverService.createDefaultService());
return true;
} catch (IllegalStateException | WebDriverException e) {
return false;
Expand Down
33 changes: 18 additions & 15 deletions java/src/org/openqa/selenium/chrome/ChromeDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
import org.openqa.selenium.remote.service.DriverService;
import org.openqa.selenium.remote.service.DriverServiceInfo;

import java.io.File;
import java.io.IOException;
Expand All @@ -41,6 +42,8 @@
*/
public class ChromeDriverService extends DriverService {

public static final String CHROME_DRIVER_NAME = "chromedriver";

/**
* System property that defines the location of the ChromeDriver executable that will be used by
* the {@link #createDefaultService() default service}.
Expand Down Expand Up @@ -135,11 +138,19 @@ public ChromeDriverService(
unmodifiableMap(new HashMap<>(environment)));
}

public String getDriverName() {
return CHROME_DRIVER_NAME;
}

public String getDriverProperty() {
return CHROME_DRIVER_EXE_PROPERTY;
}

/**
* Configures and returns a new {@link ChromeDriverService} using the default configuration. In
* this configuration, the service will use the ChromeDriver executable identified by the
* {@link #CHROME_DRIVER_EXE_PROPERTY} system property. Each service created by this method will
* be configured to use a free port on the current system.
* this configuration, the service will use the ChromeDriver executable identified by
* {@link org.openqa.selenium.remote.service.DriverFinder#getPath(DriverServiceInfo, Capabilities)}.
* Each service created by this method will be configured to use a free port on the current system.
*
* @return A new ChromeDriverService using the default configuration.
*/
Expand All @@ -149,9 +160,9 @@ public static ChromeDriverService createDefaultService() {

/**
* Configures and returns a new {@link ChromeDriverService} using the supplied configuration. In
* this configuration, the service will use the ChromeDriver executable identified by the
* {@link #CHROME_DRIVER_EXE_PROPERTY} system property. Each service created by this method will
* be configured to use a free port on the current system.
* this configuration, the service will use the ChromeDriver executable identified by
* {@link org.openqa.selenium.remote.service.DriverFinder#getPath(DriverServiceInfo, Capabilities)}.
* Each service created by this method will be configured to use a free port on the current system.
*
* @return A new ChromeDriverService using the supplied configuration from {@link ChromeOptions}.
* @deprecated Use {@link Builder#withLogLevel(ChromiumDriverLogLevel)} }
Expand All @@ -173,7 +184,7 @@ public static ChromeDriverService createServiceWithConfig(ChromeOptions options)
* @return Whether the browser driver path was found.
*/
static boolean isPresent() {
return findExePath("chromedriver", CHROME_DRIVER_EXE_PROPERTY) != null;
return findExePath(CHROME_DRIVER_NAME, CHROME_DRIVER_EXE_PROPERTY) != null;
}

/**
Expand Down Expand Up @@ -323,14 +334,6 @@ public Builder withReadableTimestamp(Boolean readableTimestamp) {
return this;
}

@Override
protected File findDefaultExecutable() {
return findExecutable(
"chromedriver", CHROME_DRIVER_EXE_PROPERTY,
"https://chromedriver.chromium.org/",
"https://chromedriver.chromium.org/downloads");
}

@Override
protected List<String> createArgs() {
if (getLogFile() == null) {
Expand Down
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/edge/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ java_export(
"//java/src/org/openqa/selenium:core",
"//java/src/org/openqa/selenium/chromium",
"//java/src/org/openqa/selenium/remote",
"//java/src/org/openqa/selenium/manager:manager",
artifact("com.google.guava:guava"),
],
)
13 changes: 12 additions & 1 deletion java/src/org/openqa/selenium/edge/EdgeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
import org.openqa.selenium.remote.service.DriverFinder;
import org.openqa.selenium.remote.service.DriverService;

import java.util.Map;
Expand All @@ -51,11 +52,21 @@ public EdgeDriver(EdgeDriverService service) {
}

public EdgeDriver(EdgeDriverService service, EdgeOptions options) {
super(new EdgeDriverCommandExecutor(service), Require.nonNull("Driver options", options), EdgeOptions.CAPABILITY);
super(generateExecutor(service, options), options, EdgeOptions.CAPABILITY);
casting = new AddHasCasting().getImplementation(getCapabilities(), getExecuteMethod());
cdp = new AddHasCdp().getImplementation(getCapabilities(), getExecuteMethod());
}

private static EdgeDriverCommandExecutor generateExecutor(EdgeDriverService service, EdgeOptions options) {
Require.nonNull("Driver service", service);
Require.nonNull("Driver options", options);
if (service.getExecutable() == null) {
String path = DriverFinder.getPath(service, options);
service.setExecutable(path);
}
return new EdgeDriverCommandExecutor(service);
}

@Beta
public static RemoteWebDriverBuilder builder() {
return RemoteWebDriver.builder().oneOf(new EdgeOptions());
Expand Down
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/edge/EdgeDriverInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebDriverInfo;
import org.openqa.selenium.chromium.ChromiumDriverInfo;
import org.openqa.selenium.remote.service.DriverFinder;

import java.util.Optional;

Expand Down Expand Up @@ -65,7 +66,7 @@ public boolean isSupportingBiDi() {
@Override
public boolean isAvailable() {
try {
EdgeDriverService.createDefaultService();
DriverFinder.getPath(EdgeDriverService.createDefaultService());
return true;
} catch (IllegalStateException | WebDriverException e) {
return false;
Expand Down
25 changes: 14 additions & 11 deletions java/src/org/openqa/selenium/edge/EdgeDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
import org.openqa.selenium.remote.service.DriverService;
import org.openqa.selenium.remote.service.DriverServiceInfo;

import java.io.File;
import java.io.IOException;
Expand All @@ -41,6 +42,8 @@
*/
public class EdgeDriverService extends DriverService {

public static final String EDGE_DRIVER_NAME = "msedgedriver";

/**
* System property that defines the location of the MSEdgeDriver executable that will be used by
* the default service.
Expand Down Expand Up @@ -110,11 +113,19 @@ public EdgeDriverService(
unmodifiableMap(new HashMap<>(environment)));
}

public String getDriverName() {
return EDGE_DRIVER_NAME;
}

public String getDriverProperty() {
return EDGE_DRIVER_EXE_PROPERTY;
}

/**
* Configures and returns a new {@link EdgeDriverService} using the default configuration. In
* this configuration, the service will use the MSEdgeDriver executable identified by the
* {@link #EDGE_DRIVER_EXE_PROPERTY} system property. Each service created by this method will
* be configured to use a free port on the current system.
* {@link org.openqa.selenium.remote.service.DriverFinder#getPath(DriverServiceInfo, Capabilities)}.
* Each service created by this method will be configured to use a free port on the current system.
*
* @return A new ChromiumEdgeDriverService using the default configuration.
*/
Expand All @@ -129,7 +140,7 @@ public static EdgeDriverService createDefaultService() {
* @return Whether the browser driver path was found.
*/
static boolean isPresent() {
return findExePath("msedgedriver", EDGE_DRIVER_EXE_PROPERTY) != null;
return findExePath(EDGE_DRIVER_NAME, EDGE_DRIVER_EXE_PROPERTY) != null;
}


Expand Down Expand Up @@ -263,14 +274,6 @@ public Builder withReadableTimestamp(Boolean readableTimestamp) {
return this;
}

@Override
protected File findDefaultExecutable() {
return findExecutable(
"msedgedriver", EDGE_DRIVER_EXE_PROPERTY,
"https://docs.microsoft.com/en-us/microsoft-edge/webdriver-chromium/",
"https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/");
}

@Override
protected List<String> createArgs() {
if (getLogFile() == null) {
Expand Down
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/firefox/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ java_export(
"//java/src/org/openqa/selenium/devtools/v85",
"//java/src/org/openqa/selenium/json",
"//java/src/org/openqa/selenium/remote",
artifact("com.google.guava:guava"),
"//java/src/org/openqa/selenium/manager:manager",
artifact("com.google.guava:guava"),
],
)
15 changes: 13 additions & 2 deletions java/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.service.DriverCommandExecutor;
import org.openqa.selenium.remote.service.DriverFinder;
import org.openqa.selenium.remote.service.DriverService;

import java.net.URI;
Expand Down Expand Up @@ -108,7 +109,7 @@ public FirefoxDriver() {
* @see #FirefoxDriver(FirefoxDriverService, FirefoxOptions)
*/
public FirefoxDriver(FirefoxOptions options) {
this(new FirefoxDriverCommandExecutor(GeckoDriverService.createDefaultService()), options);
this(GeckoDriverService.createDefaultService(), options);
}

/**
Expand All @@ -123,7 +124,17 @@ public FirefoxDriver(FirefoxDriverService service) {
}

public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options) {
this(new FirefoxDriverCommandExecutor(service), Require.nonNull("Driver options", options));
this(generateExecutor(service, options), options);
}

private static FirefoxDriverCommandExecutor generateExecutor(FirefoxDriverService service, FirefoxOptions options) {
Require.nonNull("Driver service", service);
Require.nonNull("Driver options", options);
if (service.getExecutable() == null) {
String path = DriverFinder.getPath(service, options);
service.setExecutable(path);
}
return new FirefoxDriverCommandExecutor(service);
}

private FirefoxDriver(FirefoxDriverCommandExecutor executor, FirefoxOptions options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium.firefox;

import org.openqa.selenium.remote.service.DriverService;
import org.openqa.selenium.remote.service.DriverServiceInfo;

import java.io.File;
import java.io.IOException;
Expand Down
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/firefox/GeckoDriverInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebDriverInfo;
import org.openqa.selenium.remote.service.DriverFinder;

import java.util.Optional;

Expand Down Expand Up @@ -69,7 +70,7 @@ public boolean isSupportingBiDi() {
@Override
public boolean isAvailable() {
try {
GeckoDriverService.createDefaultService();
DriverFinder.getPath(GeckoDriverService.createDefaultService());
return true;
} catch (IllegalStateException | WebDriverException e) {
return false;
Expand Down
21 changes: 11 additions & 10 deletions java/src/org/openqa/selenium/firefox/GeckoDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
*/
public class GeckoDriverService extends FirefoxDriverService {

public static final String GECKO_DRIVER_NAME = "geckodriver";

/**
* System property that defines the location of the GeckoDriver executable
* that will be used by the {@link #createDefaultService() default service}.
Expand All @@ -69,6 +71,14 @@ public GeckoDriverService(
unmodifiableMap(new HashMap<>(environment)));
}

public String getDriverName() {
return GECKO_DRIVER_NAME;
}

public String getDriverProperty() {
return GECKO_DRIVER_EXE_PROPERTY;
}

/**
* @param executable The GeckoDriver executable.
* @param port Which port to start the GeckoDriver on.
Expand Down Expand Up @@ -107,7 +117,7 @@ public static GeckoDriverService createDefaultService() {
* @return Whether the browser driver path was found.
*/
static boolean isPresent() {
return findExePath("geckodriver", GECKO_DRIVER_EXE_PROPERTY) != null;
return findExePath(GECKO_DRIVER_NAME, GECKO_DRIVER_EXE_PROPERTY) != null;
}

/**
Expand Down Expand Up @@ -163,19 +173,10 @@ public int score(Capabilities capabilities) {
*/
public Builder usingFirefoxBinary(FirefoxBinary firefoxBinary) {
Require.nonNull("Firefox binary", firefoxBinary);
checkExecutable(firefoxBinary.getFile());
this.firefoxBinary = firefoxBinary;
return this;
}

@Override
protected File findDefaultExecutable() {
return findExecutable(
"geckodriver", GECKO_DRIVER_EXE_PROPERTY,
"https://github.com/mozilla/geckodriver",
"https://github.com/mozilla/geckodriver/releases");
}

@Override
protected List<String> createArgs() {
List<String> args = new ArrayList<>();
Expand Down
1 change: 1 addition & 0 deletions java/src/org/openqa/selenium/ie/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ java_export(
"//java:auto-service",
"//java/src/org/openqa/selenium:core",
"//java/src/org/openqa/selenium/remote",
"//java/src/org/openqa/selenium/manager:manager"
],
)
Loading