Skip to content

Commit f767022

Browse files
committed
[java] add tests for Firefox HasExtensions functionality
1 parent 15dfc62 commit f767022

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

java/test/org/openqa/selenium/firefox/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ java_selenium_test_suite(
4444
"firefox",
4545
],
4646
data = [
47+
"//third_party/firebug:favourite_colour-1.1-an+fx.xpi",
4748
"//third_party/firebug:firebug-1.5.0-fx.xpi",
4849
"//third_party/firebug:mooltipass-1.1.87.xpi",
4950
],
5051
resources = [
52+
"//third_party/firebug:favourite_colour-1.1-an+fx.xpi",
5153
"//third_party/firebug:firebug-1.5.0-fx.xpi",
5254
"//third_party/firebug:mooltipass-1.1.87.xpi",
5355
],

java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@
3030
import org.openqa.selenium.ParallelTestRunner.Worker;
3131
import org.openqa.selenium.WebDriver;
3232
import org.openqa.selenium.WebElement;
33+
import org.openqa.selenium.build.InProject;
34+
import org.openqa.selenium.remote.Augmenter;
3335
import org.openqa.selenium.remote.CapabilityType;
3436
import org.openqa.selenium.remote.Command;
3537
import org.openqa.selenium.remote.CommandExecutor;
3638
import org.openqa.selenium.remote.DriverCommand;
3739
import org.openqa.selenium.remote.RemoteWebDriver;
38-
import org.openqa.selenium.remote.RemoteWebDriverBuilder;
3940
import org.openqa.selenium.remote.SessionId;
4041
import org.openqa.selenium.remote.UnreachableBrowserException;
4142
import org.openqa.selenium.support.ui.ExpectedCondition;
@@ -51,6 +52,9 @@
5152
import java.io.File;
5253
import java.io.IOException;
5354
import java.lang.reflect.Field;
55+
import java.net.MalformedURLException;
56+
import java.net.URL;
57+
import java.nio.file.Path;
5458
import java.time.Duration;
5559
import java.util.ArrayList;
5660
import java.util.List;
@@ -521,20 +525,42 @@ public void testFirefoxCanNativelyClickOverlappingElements() {
521525
}
522526

523527
@Test
524-
public void shouldAllowRemoteWebDriversToBeAugmentedWithHasExtensions() {
528+
public void shouldAddExtensions() {
529+
Path extension = InProject.locate("third_party/firebug/favourite_colour-1.1-an+fx.xpi");
530+
531+
((FirefoxDriver) driver).installExtension(extension);
532+
((FirefoxDriver) driver).uninstallExtension("favourite-colour-examples@mozilla.org");
533+
}
534+
535+
@Test
536+
public void shouldAllowRemoteWebDriverBuilderToUseHasExtensions() {
525537
WebDriver driver = RemoteWebDriver.builder()
526538
.oneOf(new FirefoxOptions())
527539
.address("http://localhost:4444/")
528540
.build();
529541

530542
try {
531-
assertThat(driver).isInstanceOf(HasExtensions.class);
532-
fail(driver.getClass().getName());
543+
Path extension = InProject.locate("third_party/firebug/favourite_colour-1.1-an+fx.xpi");
544+
((HasExtensions) driver).installExtension(extension);
545+
((HasExtensions) driver).uninstallExtension("favourite-colour-examples@mozilla.org");
533546
} finally {
534547
driver.quit();
535548
}
536549
}
537550

551+
@Test
552+
public void shouldAllowDriverToBeAugmentedWithHasExtensions() throws MalformedURLException {
553+
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/"), new FirefoxOptions());
554+
WebDriver augmentedDriver = new Augmenter().augment(driver);
555+
556+
try {
557+
Path extension = InProject.locate("third_party/firebug/favourite_colour-1.1-an+fx.xpi");
558+
((HasExtensions) augmentedDriver).installExtension(extension);
559+
((HasExtensions) augmentedDriver).uninstallExtension("favourite-colour-examples@mozilla.org");
560+
} finally {
561+
driver.quit();
562+
}
563+
}
538564

539565
private static class CustomFirefoxProfile extends FirefoxProfile {}
540566

third_party/firebug/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ licenses(["notice"])
22

33
exports_files(
44
[
5+
"favourite_colour-1.1-an+fx.xpi",
56
"firebug-1.5.0-fx.xpi",
67
"mooltipass-1.1.87.xpi",
78
],

0 commit comments

Comments
 (0)