Skip to content

Commit

Permalink
[java] Reducing code duplication, no functional changes
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Sep 29, 2019
1 parent 8adb0f2 commit c9649be
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions java/client/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
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;
Expand Down Expand Up @@ -154,30 +153,33 @@ 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) {
this(service, new FirefoxOptions());
}

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);
boolean isLegacy = (sysProperty != null && ! Boolean.parseBoolean(sysProperty))
|| options.isLegacy();
|| options.isLegacy();

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);

Expand Down

0 comments on commit c9649be

Please sign in to comment.