Skip to content

Commit

Permalink
[java] Remove deprecated methods that use capabilities in WebDrivers (#…
Browse files Browse the repository at this point in the history
…10427)

* [java] Remove deprecated methods that use capabilities in WebDrivers

Co-authored-by: Diego Molina <[email protected]>
  • Loading branch information
pujagani and diemol authored Jun 9, 2022
1 parent 05467b6 commit 7f0c563
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 102 deletions.
31 changes: 3 additions & 28 deletions java/src/org/openqa/selenium/chrome/ChromeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium.chrome;

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.Beta;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
Expand Down Expand Up @@ -59,19 +60,6 @@ public ChromeDriver(ChromeDriverService service) {
this(service, new ChromeOptions());
}

/**
* Creates a new ChromeDriver instance. The {@code capabilities} will be passed to the
* ChromeDriver service.
*
* @param capabilities The capabilities required from the ChromeDriver.
* @see #ChromeDriver(ChromeDriverService, Capabilities)
* @deprecated Use {@link #ChromeDriver(ChromeOptions)} instead.
*/
@Deprecated
public ChromeDriver(Capabilities capabilities) {
this(ChromeDriverService.createDefaultService(), capabilities);
}

/**
* Creates a new ChromeDriver instance with the specified options.
*
Expand All @@ -87,23 +75,10 @@ public ChromeDriver(ChromeOptions options) {
* started along with the driver, and shutdown upon calling {@link #quit()}.
*
* @param service The service to use.
* @param options The options to use.
* @param options The options required from ChromeDriver.
*/
public ChromeDriver(ChromeDriverService service, ChromeOptions options) {
this(service, (Capabilities) options);
}

/**
* Creates a new ChromeDriver instance. The {@code service} will be started along with the
* driver, and shutdown upon calling {@link #quit()}.
*
* @param service The service to use.
* @param capabilities The capabilities required from the ChromeDriver.
* @deprecated Use {@link #ChromeDriver(ChromeDriverService, ChromeOptions)} instead.
*/
@Deprecated
public ChromeDriver(ChromeDriverService service, Capabilities capabilities) {
super(new ChromeDriverCommandExecutor(service), capabilities, ChromeOptions.CAPABILITY);
super(new ChromeDriverCommandExecutor(service), options, ChromeOptions.CAPABILITY);
casting = new AddHasCasting().getImplementation(getCapabilities(), getExecuteMethod());
cdp = new AddHasCdp().getImplementation(getCapabilities(), getExecuteMethod());
}
Expand Down
11 changes: 4 additions & 7 deletions java/src/org/openqa/selenium/edge/EdgeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package org.openqa.selenium.edge;

import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.Beta;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chromium.ChromiumDriver;
import org.openqa.selenium.chromium.ChromiumDriverCommandExecutor;
Expand All @@ -38,7 +38,9 @@
*/
public class EdgeDriver extends ChromiumDriver {

public EdgeDriver() { this(new EdgeOptions()); }
public EdgeDriver() {
this(new EdgeOptions());
}

public EdgeDriver(EdgeOptions options) {
this(new EdgeDriverService.Builder().build(), options);
Expand All @@ -54,11 +56,6 @@ public EdgeDriver(EdgeDriverService service, EdgeOptions options) {
cdp = new AddHasCdp().getImplementation(getCapabilities(), getExecuteMethod());
}

@Deprecated
public EdgeDriver(Capabilities capabilities) {
this(new EdgeDriverService.Builder().build(), new EdgeOptions().merge(capabilities));
}

@Beta
public static RemoteWebDriverBuilder builder() {
return RemoteWebDriver.builder().oneOf(new EdgeOptions());
Expand Down
16 changes: 0 additions & 16 deletions java/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,6 @@ public class FirefoxDriver extends RemoteWebDriver
public FirefoxDriver() {
this(new FirefoxOptions());
}
/**
* @deprecated Use {@link #FirefoxDriver(FirefoxOptions)}.
*/
@Deprecated
public FirefoxDriver(Capabilities desiredCapabilities) {
this(new FirefoxOptions(Require.nonNull("Capabilities", desiredCapabilities)));
}
/**
* @deprecated Use {@link #FirefoxDriver(FirefoxDriverService, FirefoxOptions)}.
*/
@Deprecated
public FirefoxDriver(FirefoxDriverService service, Capabilities desiredCapabilities) {
this(
Require.nonNull("Driver service", service),
new FirefoxOptions(desiredCapabilities));
}

public FirefoxDriver(FirefoxOptions options) {
this(new FirefoxDriverCommandExecutor(GeckoDriverService.createDefaultService()), options);
Expand Down
35 changes: 13 additions & 22 deletions java/src/org/openqa/selenium/ie/InternetExplorerDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,6 @@ public InternetExplorerDriver() {
this(null, null);
}

/**
* @deprecated Use {@link #InternetExplorerDriver(InternetExplorerOptions)}
*/
@Deprecated
public InternetExplorerDriver(Capabilities capabilities) {
this(null, capabilities);
}

public InternetExplorerDriver(InternetExplorerOptions options) {
this(null, options);
}
Expand All @@ -161,16 +153,15 @@ public InternetExplorerDriver(InternetExplorerDriverService service) {
}

/**
* @deprecated Use {@link #InternetExplorerDriver(InternetExplorerDriverService, InternetExplorerOptions)}
* Creates a new InternetExplorerDriver instance with the specified options.
* The {@code service} will be started along with the driver, and shutdown upon
* calling {@link #quit()}.
*
* @param service The service to use.
* @param options The options required from InternetExplorerDriver.
*/
@Deprecated
public InternetExplorerDriver(InternetExplorerDriverService service, Capabilities capabilities) {
this(service, new InternetExplorerOptions(capabilities));
}

public InternetExplorerDriver(
InternetExplorerDriverService service,
InternetExplorerOptions options) {
public InternetExplorerDriver(InternetExplorerDriverService service,
InternetExplorerOptions options) {
if (options == null) {
options = new InternetExplorerOptions();
}
Expand All @@ -180,6 +171,11 @@ public InternetExplorerDriver(
run(service, options);
}

@Beta
public static RemoteWebDriverBuilder builder() {
return RemoteWebDriver.builder().oneOf(new InternetExplorerOptions());
}

private void run(InternetExplorerDriverService service, Capabilities capabilities) {
assertOnWindows();

Expand All @@ -195,11 +191,6 @@ public void setFileDetector(FileDetector detector) {
"via RemoteWebDriver");
}

@Beta
public static RemoteWebDriverBuilder builder() {
return RemoteWebDriver.builder().oneOf(new InternetExplorerOptions());
}

protected void assertOnWindows() {
Platform current = Platform.getCurrent();
if (!current.is(Platform.WINDOWS)) {
Expand Down
14 changes: 0 additions & 14 deletions java/src/org/openqa/selenium/safari/SafariDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.common.collect.ImmutableMap;

import org.openqa.selenium.Beta;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.remote.CommandInfo;
Expand Down Expand Up @@ -50,19 +49,6 @@ public SafariDriver() {
this(new SafariOptions());
}

/**
* Converts the specified {@link Capabilities} to a {@link SafariOptions}
* instance and initializes a new SafariDriver using these options.
* @see SafariOptions#fromCapabilities(Capabilities)
*
* @param desiredCapabilities capabilities requested of the driver
* @deprecated Use {@link SafariDriver(SafariOptions)} instead.
*/
@Deprecated
public SafariDriver(Capabilities desiredCapabilities) {
this(SafariOptions.fromCapabilities(desiredCapabilities));
}

/**
* Initializes a new SafariDriver using the specified {@link SafariOptions}.
*
Expand Down
26 changes: 11 additions & 15 deletions java/test/org/openqa/selenium/firefox/MarionetteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,26 @@

package org.openqa.selenium.firefox;

import static java.util.Optional.ofNullable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;
import static org.openqa.selenium.remote.CapabilityType.PAGE_LOAD_STRATEGY;

import org.junit.After;
import org.junit.Test;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.build.InProject;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.testing.JUnit4TestBase;
import org.openqa.selenium.testing.NoDriverBeforeTest;

import java.nio.file.Path;
import java.time.Duration;

import static java.util.Optional.ofNullable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;
import static org.openqa.selenium.remote.CapabilityType.PAGE_LOAD_STRATEGY;

public class MarionetteTest extends JUnit4TestBase {

Expand Down Expand Up @@ -105,7 +101,7 @@ public void canStartDriverWithSpecifiedBinaryAndProfile() {
public void canPassCapabilities() {
Capabilities caps = new ImmutableCapabilities(CapabilityType.PAGE_LOAD_STRATEGY, "none");

localDriver = new FirefoxDriver(caps);
localDriver = new FirefoxDriver(new FirefoxOptions().merge(caps));

verifyItIsMarionette(localDriver);
assertThat(((FirefoxDriver) localDriver).getCapabilities().getCapability(PAGE_LOAD_STRATEGY)).isEqualTo("none");
Expand Down Expand Up @@ -148,7 +144,7 @@ public void canSetProfileInCapabilities() {

Capabilities caps = new ImmutableCapabilities(FirefoxDriver.Capability.PROFILE, profile);

localDriver = new FirefoxDriver(caps);
localDriver = new FirefoxDriver(new FirefoxOptions().merge(caps));
wait(localDriver).until($ -> "XHTML Test Page".equals(localDriver.getTitle()));

verifyItIsMarionette(localDriver);
Expand Down

0 comments on commit 7f0c563

Please sign in to comment.