From 7627ee83d3c431859793a3969622cf272ae6b488 Mon Sep 17 00:00:00 2001 From: Titus Fortner Date: Sat, 10 Dec 2022 13:59:13 -0600 Subject: [PATCH] [java] remove deprecated Firefox capabilities and consolidate tests (#11403) --- .../selenium/firefox/FirefoxDriver.java | 7 - .../selenium/firefox/FirefoxOptions.java | 41 --- .../selenium/firefox/GeckoDriverInfo.java | 9 - .../selenium/firefox/GeckoDriverService.java | 24 +- .../org/openqa/selenium/firefox/BUILD.bazel | 1 - .../selenium/firefox/FirefoxDriverTest.java | 67 ++--- .../selenium/firefox/MarionetteTest.java | 256 ------------------ 7 files changed, 28 insertions(+), 377 deletions(-) delete mode 100644 java/test/org/openqa/selenium/firefox/MarionetteTest.java diff --git a/java/src/org/openqa/selenium/firefox/FirefoxDriver.java b/java/src/org/openqa/selenium/firefox/FirefoxDriver.java index f821536d85d2f..29ad2bc6fbe2b 100644 --- a/java/src/org/openqa/selenium/firefox/FirefoxDriver.java +++ b/java/src/org/openqa/selenium/firefox/FirefoxDriver.java @@ -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) { diff --git a/java/src/org/openqa/selenium/firefox/FirefoxOptions.java b/java/src/org/openqa/selenium/firefox/FirefoxOptions.java index 2ef1d21bbecdb..3fad691ae914d 100644 --- a/java/src/org/openqa/selenium/firefox/FirefoxOptions.java +++ b/java/src/org/openqa/selenium/firefox/FirefoxOptions.java @@ -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; @@ -295,45 +293,6 @@ public FirefoxOptions setAndroidIntentArguments(List 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); } diff --git a/java/src/org/openqa/selenium/firefox/GeckoDriverInfo.java b/java/src/org/openqa/selenium/firefox/GeckoDriverInfo.java index 721b5a3808132..fd4496619d3e6 100644 --- a/java/src/org/openqa/selenium/firefox/GeckoDriverInfo.java +++ b/java/src/org/openqa/selenium/firefox/GeckoDriverInfo.java @@ -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; @@ -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; } @@ -93,10 +88,6 @@ public Optional createDriver(Capabilities capabilities) return Optional.empty(); } - if (capabilities.is(MARIONETTE)) { - return Optional.empty(); - } - return Optional.of(new FirefoxDriver(new FirefoxOptions().merge(capabilities))); } } diff --git a/java/src/org/openqa/selenium/firefox/GeckoDriverService.java b/java/src/org/openqa/selenium/firefox/GeckoDriverService.java index 94c093fab5a5f..d0784035347ae 100644 --- a/java/src/org/openqa/selenium/firefox/GeckoDriverService.java +++ b/java/src/org/openqa/selenium/firefox/GeckoDriverService.java @@ -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 @@ -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)) { diff --git a/java/test/org/openqa/selenium/firefox/BUILD.bazel b/java/test/org/openqa/selenium/firefox/BUILD.bazel index 738e8857f4d46..c57d053a931ca 100644 --- a/java/test/org/openqa/selenium/firefox/BUILD.bazel +++ b/java/test/org/openqa/selenium/firefox/BUILD.bazel @@ -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", ] diff --git a/java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java b/java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java index f7c3a3d9ec628..01d7f7587363a 100644 --- a/java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java +++ b/java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java @@ -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; @@ -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; @@ -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()); @@ -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() { @@ -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(); } @@ -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() { @@ -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 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 urlToBe(final String expectedUrl) { + return driver1 -> expectedUrl.equals(driver1.getCurrentUrl()); } @Test diff --git a/java/test/org/openqa/selenium/firefox/MarionetteTest.java b/java/test/org/openqa/selenium/firefox/MarionetteTest.java deleted file mode 100644 index f40f1261975f3..0000000000000 --- a/java/test/org/openqa/selenium/firefox/MarionetteTest.java +++ /dev/null @@ -1,256 +0,0 @@ -// Licensed to the Software Freedom Conservancy (SFC) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The SFC licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -package org.openqa.selenium.firefox; - -import org.junit.jupiter.api.Assumptions; -import org.junit.jupiter.api.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.testing.JupiterTestBase; -import org.openqa.selenium.testing.NoDriverBeforeTest; - -import java.nio.file.Path; - -import static java.util.Optional.ofNullable; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assumptions.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; - -class MarionetteTest extends JupiterTestBase { - - private static final String EXT_PATH = "common/extensions/webextensions-selenium-example.xpi"; - - @Test - @NoDriverBeforeTest - public void canStartDriverWithEmptyOptions() { - localDriver = new FirefoxDriver(new FirefoxOptions()); - verifyItIsMarionette(localDriver); - } - - @Test - @NoDriverBeforeTest - public void canStartDriverWithNoParameters() { - localDriver = new FirefoxDriver(); - verifyItIsMarionette(localDriver); - } - - @Test - @NoDriverBeforeTest - public void canStartDriverWithSpecifiedBinary() { - FirefoxBinary binary = spy(new FirefoxBinary()); - - localDriver = new FirefoxDriver(new FirefoxOptions().setBinary(binary)); - - verifyItIsMarionette(localDriver); - verify(binary, atLeastOnce()).getPath(); - } - - @Test - @NoDriverBeforeTest - public void canStartDriverWithSpecifiedProfile() { - FirefoxProfile profile = new FirefoxProfile(); - profile.setPreference("browser.startup.page", 1); - profile.setPreference("browser.startup.homepage", pages.xhtmlTestPage); - - localDriver = new FirefoxDriver(new FirefoxOptions().setProfile(profile)); - wait(localDriver).until($ -> "XHTML Test Page".equals(localDriver.getTitle())); - - verifyItIsMarionette(localDriver); - } - - @Test - @NoDriverBeforeTest - public void canStartDriverWithSpecifiedBinaryAndProfile() { - FirefoxBinary binary = spy(new FirefoxBinary()); - - FirefoxProfile profile = new FirefoxProfile(); - profile.setPreference("browser.startup.page", 1); - profile.setPreference("browser.startup.homepage", pages.xhtmlTestPage); - - localDriver = new FirefoxDriver(new FirefoxOptions().setBinary(binary).setProfile(profile)); - wait(localDriver).until($ -> "XHTML Test Page".equals(localDriver.getTitle())); - - verifyItIsMarionette(localDriver); - verify(binary, atLeastOnce()).getPath(); - } - - @Test - @NoDriverBeforeTest - public void canPassCapabilities() { - Capabilities caps = new ImmutableCapabilities(CapabilityType.PAGE_LOAD_STRATEGY, "none"); - - localDriver = new FirefoxDriver(new FirefoxOptions().merge(caps)); - - verifyItIsMarionette(localDriver); - assertThat(((FirefoxDriver) localDriver).getCapabilities().getCapability(PAGE_LOAD_STRATEGY)).isEqualTo("none"); - } - - @Test - @NoDriverBeforeTest - public void canSetPreferencesInFirefoxOptions() { - FirefoxOptions options = new FirefoxOptions() - .addPreference("browser.startup.page", 1) - .addPreference("browser.startup.homepage", pages.xhtmlTestPage); - - localDriver = new FirefoxDriver(options); - wait(localDriver).until($ -> "XHTML Test Page".equals(localDriver.getTitle())); - - verifyItIsMarionette(localDriver); - } - - @Test - @NoDriverBeforeTest - public void canSetProfileInFirefoxOptions() { - FirefoxProfile profile = new FirefoxProfile(); - profile.setPreference("browser.startup.page", 1); - profile.setPreference("browser.startup.homepage", pages.xhtmlTestPage); - - FirefoxOptions options = new FirefoxOptions().setProfile(profile); - - localDriver = new FirefoxDriver(options); - wait(localDriver).until($ -> "XHTML Test Page".equals(localDriver.getTitle())); - - verifyItIsMarionette(localDriver); - } - - @Test - @NoDriverBeforeTest - public void canSetProfileInCapabilities() { - FirefoxProfile profile = new FirefoxProfile(); - profile.setPreference("browser.startup.page", 1); - profile.setPreference("browser.startup.homepage", pages.xhtmlTestPage); - - Capabilities caps = new ImmutableCapabilities(FirefoxDriver.Capability.PROFILE, profile); - - localDriver = new FirefoxDriver(new FirefoxOptions().merge(caps)); - wait(localDriver).until($ -> "XHTML Test Page".equals(localDriver.getTitle())); - - verifyItIsMarionette(localDriver); - } - - @Test - @NoDriverBeforeTest - public void canUseSameProfileInCapabilitiesAndDirectly() { - FirefoxProfile profile = new FirefoxProfile(); - profile.setPreference("browser.startup.page", 1); - profile.setPreference("browser.startup.homepage", pages.xhtmlTestPage); - - Capabilities caps = new ImmutableCapabilities(FirefoxDriver.Capability.PROFILE, profile); - - localDriver = new FirefoxDriver( - new FirefoxOptions() - .setProfile(profile) - .merge(caps)); - wait(localDriver).until($ -> "XHTML Test Page".equals(localDriver.getTitle())); - - verifyItIsMarionette(localDriver); - } - - @Test - @NoDriverBeforeTest - public void canPassCapabilitiesBinaryAndProfileSeparately() { - FirefoxBinary binary = spy(new FirefoxBinary()); - - FirefoxProfile profile = new FirefoxProfile(); - profile.setPreference("browser.startup.page", 1); - profile.setPreference("browser.startup.homepage", pages.xhtmlTestPage); - - Capabilities caps = new ImmutableCapabilities(CapabilityType.PAGE_LOAD_STRATEGY, "none"); - - localDriver = new FirefoxDriver( - new FirefoxOptions() - .setBinary(binary) - .setProfile(profile) - .merge(caps)); - wait(localDriver).until($ -> "XHTML Test Page".equals(localDriver.getTitle())); - - verifyItIsMarionette(localDriver); - verify(binary, atLeastOnce()).getPath(); - assertThat(((FirefoxDriver) localDriver).getCapabilities().getCapability(PAGE_LOAD_STRATEGY)).isEqualTo("none"); - } - - @Test - @NoDriverBeforeTest - public void canSetPreferencesAndProfileInFirefoxOptions() { - FirefoxProfile profile = new FirefoxProfile(); - profile.setPreference("browser.startup.page", 1); - profile.setPreference("browser.startup.homepage", pages.xhtmlTestPage); - - FirefoxOptions options = new FirefoxOptions() - .setProfile(profile) - .addPreference("browser.startup.homepage", pages.javascriptPage); - - localDriver = new FirefoxDriver(options); - wait(localDriver).until($ -> "Testing Javascript".equals(localDriver.getTitle())); - - verifyItIsMarionette(localDriver); - } - - @Test - @NoDriverBeforeTest - public void canSetPageLoadStrategyViaOptions() { - localDriver = new FirefoxDriver( - new FirefoxOptions().setPageLoadStrategy(PageLoadStrategy.NONE)); - - verifyItIsMarionette(localDriver); - assertThat(((FirefoxDriver) localDriver).getCapabilities().getCapability(PAGE_LOAD_STRATEGY)).isEqualTo("none"); - } - - @Test - @NoDriverBeforeTest - public void canSetInsecureCertSupportViaOptions() { - localDriver = new FirefoxDriver(new FirefoxOptions().setAcceptInsecureCerts(true)); - - verifyItIsMarionette(localDriver); - assertThat(((FirefoxDriver) localDriver).getCapabilities().getCapability(ACCEPT_INSECURE_CERTS)).isEqualTo(true); - } - - @Test - @NoDriverBeforeTest - public void canStartHeadless() { - localDriver = new FirefoxDriver(new FirefoxOptions().setHeadless(true)); - - verifyItIsMarionette(localDriver); - assertThat(((FirefoxDriver) localDriver).getCapabilities().getCapability("moz:headless")).isEqualTo(true); - } - - @Test - @NoDriverBeforeTest - public void canInstallAndUninstallExtensionsOnTheFly() { - assumeTrue(driver instanceof FirefoxDriver); - FirefoxDriver localDriver = (FirefoxDriver) driver; - Path extension = InProject.locate(EXT_PATH); - String extId = localDriver.installExtension(extension); - assertThat(extId).isEqualTo("webextensions-selenium-example@example.com"); - localDriver.uninstallExtension(extId); - } - - private void verifyItIsMarionette(WebDriver driver) { - FirefoxDriver firefoxDriver = (FirefoxDriver) driver; - assertThat(ofNullable(firefoxDriver.getCapabilities().getCapability("moz:processID")) - .orElse(firefoxDriver.getCapabilities().getCapability("processId"))).isNotNull(); - } -}