[java] Reducing code duplication, no functional changes
import org.openqa.selenium.html5.LocalStorage;
import org.openqa.selenium.html5.SessionStorage;
import org.openqa.selenium.html5.WebStorage;
-import org.openqa.selenium.remote.CommandExecutor;
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.FileDetector;
import org.openqa.selenium.remote.RemoteWebDriver;
@@ -154,8 +153,7 @@ public FirefoxDriver(FirefoxDriverService service, Capabilities desiredCapabilit
}
public FirefoxDriver(FirefoxOptions options) {
- super(toExecutor(options), dropCapabilities(options));
- webStorage = new RemoteWebStorage(getExecuteMethod());
+ this(toExecutor(options), options);
}
public FirefoxDriver(FirefoxDriverService service) {
@@ -163,11 +161,15 @@ public FirefoxDriver(FirefoxDriverService service) {
}
public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options) {
- super(new FirefoxDriverCommandExecutor(service), dropCapabilities(options));
+ this(new FirefoxDriverCommandExecutor(service), options);
+ }
+
+ private FirefoxDriver(FirefoxDriverCommandExecutor executor, FirefoxOptions options) {
+ super(executor, dropCapabilities(options));
webStorage = new RemoteWebStorage(getExecuteMethod());
}
- private static CommandExecutor toExecutor(FirefoxOptions options) {
+ private static FirefoxDriverCommandExecutor toExecutor(FirefoxOptions options) {
Objects.requireNonNull(options, "No options to construct executor from");
String sysProperty = System.getProperty(SystemProperty.DRIVER_USE_MARIONETTE);
@@ -177,7 +179,7 @@ private static CommandExecutor toExecutor(FirefoxOptions options) {
FirefoxDriverService.Builder<?, ?> builder =
StreamSupport.stream(ServiceLoader.load(DriverService.Builder.class).spliterator(), false)
.filter(b -> b instanceof FirefoxDriverService.Builder)
- .map(b -> (FirefoxDriverService.Builder) b)
+ .map(FirefoxDriverService.Builder.class::cast)
.filter(b -> b.isLegacy() == isLegacy)
.findFirst().orElseThrow(WebDriverException::new);
