Skip to content

Commit

Permalink
[java] add tests for Firefox HasExtensions functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 20, 2021
1 parent 15dfc62 commit f767022
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
2 changes: 2 additions & 0 deletions java/test/org/openqa/selenium/firefox/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down
34 changes: 30 additions & 4 deletions java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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("[email protected]");
}

@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("[email protected]");
} 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("[email protected]");
} finally {
driver.quit();
}
}

private static class CustomFirefoxProfile extends FirefoxProfile {}

Expand Down
1 change: 1 addition & 0 deletions third_party/firebug/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
Expand Down

0 comments on commit f767022

Please sign in to comment.