Skip to content

Commit

Permalink
[java] remove deprecated Firefox capabilities and consolidate tests (S…
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Dec 10, 2022
1 parent 29fc508 commit 7627ee8
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 377 deletions.
7 changes: 0 additions & 7 deletions java/src/org/openqa/selenium/firefox/FirefoxDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,6 @@ public static final class SystemProperty {
public static final String BROWSER_PROFILE = "webdriver.firefox.profile";
}

public static final class Capability {

public static final String BINARY = "firefox_binary";
public static final String PROFILE = "firefox_profile";
public static final String MARIONETTE = "marionette";
}

private static class FirefoxDriverCommandExecutor extends DriverCommandExecutor {

public FirefoxDriverCommandExecutor(DriverService service) {
Expand Down
41 changes: 0 additions & 41 deletions java/src/org/openqa/selenium/firefox/FirefoxOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
package org.openqa.selenium.firefox;

import static java.util.stream.Collectors.toMap;
import static org.openqa.selenium.firefox.FirefoxDriver.Capability.BINARY;
import static org.openqa.selenium.firefox.FirefoxDriver.Capability.PROFILE;
import static org.openqa.selenium.remote.Browser.FIREFOX;

import org.openqa.selenium.Capabilities;
Expand Down Expand Up @@ -295,45 +293,6 @@ public FirefoxOptions setAndroidIntentArguments(List<String> args) {
return setFirefoxOption("androidIntentArguments", args);
}

@Override
public void setCapability(String key, Object value) {
Require.nonNull("Capability name", key);
Require.nonNull("Value", value);

switch (key) {
case BINARY:
if (value instanceof FirefoxBinary) {
setBinary((FirefoxBinary) value);
} else if (value instanceof Path) {
setBinary((Path) value);
} else if (value instanceof String) {
setBinary((String) value);
} else {
throw new IllegalArgumentException("Unable to set binary from " + value);
}
break;

case PROFILE:
if (value instanceof FirefoxProfile) {
setProfile((FirefoxProfile) value);
} else if (value instanceof String) {
try {
FirefoxProfile profile = FirefoxProfile.fromJson((String) value);
setProfile(profile);
} catch (IOException e) {
throw new WebDriverException(e);
}
} else {
throw new WebDriverException("Unexpected value for profile: " + value);
}
break;

default:
// Do nothing
}
super.setCapability(key, value);
}

private FirefoxOptions setFirefoxOption(Keys key, Object value) {
return setFirefoxOption(key.key(), value);
}
Expand Down
9 changes: 0 additions & 9 deletions java/src/org/openqa/selenium/firefox/GeckoDriverInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.openqa.selenium.firefox;

import static org.openqa.selenium.firefox.FirefoxDriver.Capability.MARIONETTE;
import static org.openqa.selenium.remote.Browser.FIREFOX;
import static org.openqa.selenium.remote.CapabilityType.BROWSER_NAME;

Expand Down Expand Up @@ -47,10 +46,6 @@ public Capabilities getCanonicalCapabilities() {

@Override
public boolean isSupporting(Capabilities capabilities) {
if (capabilities.is(MARIONETTE)) {
return false;
}

if (FIREFOX.is(capabilities)) {
return true;
}
Expand Down Expand Up @@ -93,10 +88,6 @@ public Optional<WebDriver> createDriver(Capabilities capabilities)
return Optional.empty();
}

if (capabilities.is(MARIONETTE)) {
return Optional.empty();
}

return Optional.of(new FirefoxDriver(new FirefoxOptions().merge(capabilities)));
}
}
24 changes: 1 addition & 23 deletions java/src/org/openqa/selenium/firefox/GeckoDriverService.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,7 @@ public static GeckoDriverService createDefaultService() {
}

static GeckoDriverService createDefaultService(Capabilities caps) {
Builder builder = new Builder();

Object binary = caps.getCapability(FirefoxDriver.Capability.BINARY);
if (binary != null) {
FirefoxBinary actualBinary;
if (binary instanceof FirefoxBinary) {
actualBinary = (FirefoxBinary) binary;
} else if (binary instanceof String) {
actualBinary = new FirefoxBinary(new File(String.valueOf(binary)));
} else {
throw new IllegalArgumentException(
"Expected binary to be a string or a binary: " + binary);
}

builder.usingFirefoxBinary(actualBinary);
}

return builder.build();
return createDefaultService();
}

@Override
Expand All @@ -139,11 +122,6 @@ public Builder() {

@Override
public int score(Capabilities capabilities) {
if (capabilities.getCapability(FirefoxDriver.Capability.MARIONETTE) != null
&& ! capabilities.is(FirefoxDriver.Capability.MARIONETTE)) {
return 0;
}

int score = 0;

if (FIREFOX.is(capabilities)) {
Expand Down
1 change: 0 additions & 1 deletion java/test/org/openqa/selenium/firefox/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ load("//java:defs.bzl", "JUNIT5_DEPS", "java_selenium_test_suite", "java_test_su

LARGE_TESTS = [
"FirefoxDriverTest.java",
"MarionetteTest.java",
"TakesFullPageScreenshotTest.java",
]

Expand Down
67 changes: 27 additions & 40 deletions java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import org.openqa.selenium.ImmutableCapabilities;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.ParallelTestRunner;
import org.openqa.selenium.ParallelTestRunner.Worker;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.build.InProject;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.Command;
import org.openqa.selenium.remote.CommandExecutor;
import org.openqa.selenium.remote.DriverCommand;
Expand Down Expand Up @@ -72,6 +74,7 @@
import static org.mockito.Mockito.verify;
import static org.openqa.selenium.WaitingConditions.elementValueToEqual;
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;
import static org.openqa.selenium.remote.CapabilityType.PAGE_LOAD_STRATEGY;
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
import static org.openqa.selenium.testing.drivers.Browser.FIREFOX;

Expand Down Expand Up @@ -135,7 +138,6 @@ public void canStartDriverWithNoParameters() {
}

@Test
@Ignore(value = FIREFOX, reason = "Assumed to be covered by tests for GeckoDriverService")
@NoDriverBeforeTest
public void canStartDriverWithSpecifiedBinary() {
FirefoxBinary binary = spy(new FirefoxBinary());
Expand Down Expand Up @@ -182,27 +184,6 @@ public void canSetProfileInFirefoxOptions() {
wait(localDriver).until($ -> "XHTML Test Page".equals(localDriver.getTitle()));
}

@Test
@Ignore(value = FIREFOX, reason = "Assumed to be covered by tests for GeckoDriverService")
@NoDriverBeforeTest
public void canSetBinaryInCapabilities() {
FirefoxBinary binary = spy(new FirefoxBinary());
Capabilities caps = new ImmutableCapabilities(FirefoxDriver.Capability.BINARY, binary);

localDriver = new WebDriverBuilder().get(caps);

verify(binary, atLeastOnce()).getPath();
}

@Test
@NoDriverBeforeTest
public void canSetBinaryPathInCapabilities() {
String binPath = new FirefoxBinary().getPath();
Capabilities caps = new ImmutableCapabilities(FirefoxDriver.Capability.BINARY, binPath);

localDriver = new WebDriverBuilder().get(caps);
}

@Test
@NoDriverBeforeTest
public void canSetPreferencesAndProfileInFirefoxOptions() {
Expand Down Expand Up @@ -327,16 +308,13 @@ public void shouldBeAbleToStartANamedProfile() {
}

@Test
@Timeout(60)
@Ignore(FIREFOX)
@Timeout(10)
@NoDriverBeforeTest
public void shouldBeAbleToStartANewInstanceEvenWithVerboseLogging() {
FirefoxBinary binary = new FirefoxBinary();
GeckoDriverService service = new GeckoDriverService.Builder()
.usingFirefoxBinary(binary)
.withEnvironment(ImmutableMap.of("NSPR_LOG_MODULES", "all:5"))
.build();

// We will have an infinite hang if this driver does not start properly.
new FirefoxDriver(service).quit();
}

Expand All @@ -354,6 +332,16 @@ public void shouldBeAbleToPassCommandLineOptions() {
assertThat(size.height).isLessThan(650);
}

@Test
@NoDriverBeforeTest
public void canPassCapabilities() {
Capabilities caps = new ImmutableCapabilities(CapabilityType.PAGE_LOAD_STRATEGY, "none");

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

assertThat(((FirefoxDriver) localDriver).getCapabilities().getCapability(PAGE_LOAD_STRATEGY)).isEqualTo("none");
}

@Test
@NoDriverBeforeTest
public void canBlockInsecureCerts() {
Expand All @@ -364,24 +352,23 @@ public void canBlockInsecureCerts() {

@Test
@NoDriverBeforeTest
public void shouldAllowUserToSuccessfullyOverrideTheHomePage() {
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.startup.page", "1");
profile.setPreference("browser.startup.homepage", pages.javascriptPage);
public void canSetPageLoadStrategyViaOptions() {
localDriver = new FirefoxDriver(
new FirefoxOptions().setPageLoadStrategy(PageLoadStrategy.NONE));

localDriver = new WebDriverBuilder().get(new FirefoxOptions().setProfile(profile));
new WebDriverWait(localDriver, Duration.ofSeconds(30)).until(urlToBe(pages.javascriptPage));
assertThat(((FirefoxDriver) localDriver).getCapabilities().getCapability(PAGE_LOAD_STRATEGY)).isEqualTo("none");
}

private ExpectedCondition<Boolean> urlToBe(final String expectedUrl) {
return driver1 -> expectedUrl.equals(driver1.getCurrentUrl());
@Test
@NoDriverBeforeTest
public void canStartHeadless() {
localDriver = new FirefoxDriver(new FirefoxOptions().setHeadless(true));

assertThat(((FirefoxDriver) localDriver).getCapabilities().getCapability("moz:headless")).isEqualTo(true);
}

@Test
@Ignore(value = FIREFOX, issue = "https://github.com/mozilla/geckodriver/issues/273")
public void canAccessUrlProtectedByBasicAuth() {
driver.get(appServer.whereIsWithCredentials("basicAuth", "test", "test"));
assertThat(driver.findElement(By.tagName("h1")).getText()).isEqualTo("authorized");
private ExpectedCondition<Boolean> urlToBe(final String expectedUrl) {
return driver1 -> expectedUrl.equals(driver1.getCurrentUrl());
}

@Test
Expand Down
Loading

0 comments on commit 7627ee8

Please sign in to comment.