From f76702247c055fa6285fac1eac165ad8f188b398 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Mon, 20 Sep 2021 16:23:55 -0500 Subject: [PATCH] [java] add tests for Firefox HasExtensions functionality --- .../org/openqa/selenium/firefox/BUILD.bazel | 2 ++ .../selenium/firefox/FirefoxDriverTest.java | 34 ++++++++++++++++--- third_party/firebug/BUILD.bazel | 1 + 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/java/test/org/openqa/selenium/firefox/BUILD.bazel b/java/test/org/openqa/selenium/firefox/BUILD.bazel index 41a33a6a4f250..e368296686e74 100644 --- a/java/test/org/openqa/selenium/firefox/BUILD.bazel +++ b/java/test/org/openqa/selenium/firefox/BUILD.bazel @@ -44,10 +44,12 @@ java_selenium_test_suite( "firefox", ], data = [ + "//third_party/firebug:favourite_colour-1.1-an+fx.xpi", "//third_party/firebug:firebug-1.5.0-fx.xpi", "//third_party/firebug:mooltipass-1.1.87.xpi", ], resources = [ + "//third_party/firebug:favourite_colour-1.1-an+fx.xpi", "//third_party/firebug:firebug-1.5.0-fx.xpi", "//third_party/firebug:mooltipass-1.1.87.xpi", ], diff --git a/java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java b/java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java index e760d32c1d21b..e4df5ac2058f5 100644 --- a/java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java +++ b/java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java @@ -30,12 +30,13 @@ 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.Augmenter; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.Command; import org.openqa.selenium.remote.CommandExecutor; import org.openqa.selenium.remote.DriverCommand; import org.openqa.selenium.remote.RemoteWebDriver; -import org.openqa.selenium.remote.RemoteWebDriverBuilder; import org.openqa.selenium.remote.SessionId; import org.openqa.selenium.remote.UnreachableBrowserException; import org.openqa.selenium.support.ui.ExpectedCondition; @@ -51,6 +52,9 @@ import java.io.File; import java.io.IOException; import java.lang.reflect.Field; +import java.net.MalformedURLException; +import java.net.URL; +import java.nio.file.Path; import java.time.Duration; import java.util.ArrayList; import java.util.List; @@ -521,20 +525,42 @@ public void testFirefoxCanNativelyClickOverlappingElements() { } @Test - public void shouldAllowRemoteWebDriversToBeAugmentedWithHasExtensions() { + public void shouldAddExtensions() { + Path extension = InProject.locate("third_party/firebug/favourite_colour-1.1-an+fx.xpi"); + + ((FirefoxDriver) driver).installExtension(extension); + ((FirefoxDriver) driver).uninstallExtension("favourite-colour-examples@mozilla.org"); + } + + @Test + public void shouldAllowRemoteWebDriverBuilderToUseHasExtensions() { WebDriver driver = RemoteWebDriver.builder() .oneOf(new FirefoxOptions()) .address("http://localhost:4444/") .build(); try { - assertThat(driver).isInstanceOf(HasExtensions.class); - fail(driver.getClass().getName()); + Path extension = InProject.locate("third_party/firebug/favourite_colour-1.1-an+fx.xpi"); + ((HasExtensions) driver).installExtension(extension); + ((HasExtensions) driver).uninstallExtension("favourite-colour-examples@mozilla.org"); } finally { driver.quit(); } } + @Test + public void shouldAllowDriverToBeAugmentedWithHasExtensions() throws MalformedURLException { + WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/"), new FirefoxOptions()); + WebDriver augmentedDriver = new Augmenter().augment(driver); + + try { + Path extension = InProject.locate("third_party/firebug/favourite_colour-1.1-an+fx.xpi"); + ((HasExtensions) augmentedDriver).installExtension(extension); + ((HasExtensions) augmentedDriver).uninstallExtension("favourite-colour-examples@mozilla.org"); + } finally { + driver.quit(); + } + } private static class CustomFirefoxProfile extends FirefoxProfile {} diff --git a/third_party/firebug/BUILD.bazel b/third_party/firebug/BUILD.bazel index 87e45edaa8f75..38154487badd6 100644 --- a/third_party/firebug/BUILD.bazel +++ b/third_party/firebug/BUILD.bazel @@ -2,6 +2,7 @@ licenses(["notice"]) exports_files( [ + "favourite_colour-1.1-an+fx.xpi", "firebug-1.5.0-fx.xpi", "mooltipass-1.1.87.xpi", ],