Skip to content

Commit

Permalink
[java] tidy up minor differences between the service classes
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Dec 11, 2022
1 parent 2af020f commit e135eec
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
3 changes: 2 additions & 1 deletion java/src/org/openqa/selenium/chrome/ChromeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chromium.ChromiumDriver;
import org.openqa.selenium.chromium.ChromiumDriverCommandExecutor;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
Expand Down Expand Up @@ -78,7 +79,7 @@ public ChromeDriver(ChromeOptions options) {
* @param options The options required from ChromeDriver.
*/
public ChromeDriver(ChromeDriverService service, ChromeOptions options) {
super(new ChromeDriverCommandExecutor(service), options, ChromeOptions.CAPABILITY);
super(new ChromeDriverCommandExecutor(service), Require.nonNull("Driver options", options), ChromeOptions.CAPABILITY);
casting = new AddHasCasting().getImplementation(getCapabilities(), getExecuteMethod());
cdp = new AddHasCdp().getImplementation(getCapabilities(), getExecuteMethod());
}
Expand Down
22 changes: 21 additions & 1 deletion java/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,40 @@ public class FirefoxDriver extends RemoteWebDriver
private Connection connection;
private DevTools devTools;
private BiDi biDi;

/**
* Creates a new FirefoxDriver using the {@link GeckoDriverService#createDefaultService)}
* server configuration.
*
* @see #FirefoxDriver(FirefoxDriverService, FirefoxOptions)
*/
public FirefoxDriver() {
this(new FirefoxOptions());
}

/**
* Creates a new FirefoxDriver instance with the specified options.
*
* @param options The options to use.
* @see #FirefoxDriver(FirefoxDriverService, FirefoxOptions)
*/
public FirefoxDriver(FirefoxOptions options) {
this(new FirefoxDriverCommandExecutor(GeckoDriverService.createDefaultService()), options);
}

/**
* Creates a new FirefoxDriver instance. The {@code service} will be started along with the driver,
* and shutdown upon calling {@link #quit()}.
*
* @param service The service to use.
* @see RemoteWebDriver#RemoteWebDriver(org.openqa.selenium.remote.CommandExecutor, Capabilities)
*/
public FirefoxDriver(FirefoxDriverService service) {
this(service, new FirefoxOptions());
}

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

private FirefoxDriver(FirefoxDriverCommandExecutor executor, FirefoxOptions options) {
Expand Down
15 changes: 13 additions & 2 deletions java/src/org/openqa/selenium/firefox/GeckoDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.openqa.selenium.remote.Browser.FIREFOX;

Expand All @@ -62,7 +64,9 @@ public GeckoDriverService(
int port,
List<String> args,
Map<String, String> environment) throws IOException {
super(executable, port, DEFAULT_TIMEOUT, args, environment);
super(executable, port, DEFAULT_TIMEOUT,
unmodifiableList(new ArrayList<>(args)),
unmodifiableMap(new HashMap<>(environment)));
}

/**
Expand All @@ -79,7 +83,9 @@ public GeckoDriverService(
Duration timeout,
List<String> args,
Map<String, String> environment) throws IOException {
super(executable, port, timeout, args, environment);
super(executable, port, timeout,
unmodifiableList(new ArrayList<>(args)),
unmodifiableMap(new HashMap<>(environment)));
}

/**
Expand All @@ -94,6 +100,11 @@ public static GeckoDriverService createDefaultService() {
return new Builder().build();
}

/**
*
* @param caps Capabilities instance
* @return default GeckoDriverService
*/
static GeckoDriverService createDefaultService(Capabilities caps) {
return createDefaultService();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
import static org.openqa.selenium.remote.Browser.IE;

/**
Expand Down Expand Up @@ -80,7 +82,9 @@ public class InternetExplorerDriverService extends DriverService {
*/
private InternetExplorerDriverService(File executable, int port, Duration timeout, List<String> args,
Map<String, String> environment) throws IOException {
super(executable, port, timeout, args, environment);
super(executable, port, timeout,
unmodifiableList(new ArrayList<>(args)),
unmodifiableMap(new HashMap<>(environment)));
}

/**
Expand Down
8 changes: 7 additions & 1 deletion java/src/org/openqa/selenium/safari/SafariDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.openqa.selenium.Platform.MAC;
import static org.openqa.selenium.remote.Browser.SAFARI;
Expand All @@ -51,7 +55,9 @@ public SafariDriverService(
int port,
List<String> args,
Map<String, String> environment) throws IOException {
super(executable, port, DEFAULT_TIMEOUT, args, environment);
super(executable, port, DEFAULT_TIMEOUT,
unmodifiableList(new ArrayList<>(args)),
unmodifiableMap(new HashMap<>(environment)));
}

public SafariDriverService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.openqa.selenium.remote.Browser.SAFARI_TECH_PREVIEW;

Expand All @@ -50,7 +54,9 @@ public SafariTechPreviewDriverService(
int port,
List<String> args,
Map<String, String> environment) throws IOException {
super(executable, port, DEFAULT_TIMEOUT, args, environment);
super(executable, port, DEFAULT_TIMEOUT,
unmodifiableList(new ArrayList<>(args)),
unmodifiableMap(new HashMap<>(environment)));
}

public SafariTechPreviewDriverService(
Expand All @@ -59,7 +65,9 @@ public SafariTechPreviewDriverService(
Duration timeout,
List<String> args,
Map<String, String> environment) throws IOException {
super(executable, port, timeout, args, environment);
super(executable, port, timeout,
unmodifiableList(new ArrayList<>(args)),
unmodifiableMap(new HashMap<>(environment)));
}

public static SafariTechPreviewDriverService createDefaultService() {
Expand Down

0 comments on commit e135eec

Please sign in to comment.