|
| 1 | +package org.openqa.selenium.firefox; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | +import static org.openqa.selenium.firefox.FirefoxAssumptions.assumeDefaultBrowserLocationUsed; |
| 5 | + |
| 6 | +import java.nio.file.Path; |
| 7 | +import org.junit.jupiter.api.BeforeEach; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | +import org.openqa.selenium.By; |
| 10 | +import org.openqa.selenium.WebElement; |
| 11 | +import org.openqa.selenium.build.InProject; |
| 12 | +import org.openqa.selenium.testing.JupiterTestBase; |
| 13 | + |
| 14 | +public class ExtensionsTest extends JupiterTestBase { |
| 15 | + |
| 16 | + private static final String EXT_XPI = "common/extensions/webextensions-selenium-example.xpi"; |
| 17 | + private static final String EXT_SIGNED_ZIP = |
| 18 | + "common/extensions/webextensions-selenium-example.zip"; |
| 19 | + private static final String EXT_UNSIGNED_ZIP = |
| 20 | + "common/extensions/webextensions-selenium-example-unsigned.zip"; |
| 21 | + private static final String EXT_SIGNED_DIR = |
| 22 | + "common/extensions/webextensions-selenium-example-signed"; |
| 23 | + private static final String EXT_UNSIGNED_DIR = "common/extensions/webextensions-selenium-example"; |
| 24 | + |
| 25 | + @BeforeEach |
| 26 | + public void checkTestsAreExpectedToRunAndPass() { |
| 27 | + // I can't figure out why this is failing in EngFlow, but XPIs are no |
| 28 | + // longer actively developed (being replaced by Web Extensions), so I |
| 29 | + // think it's okay to skip this test if we're running remotely. |
| 30 | + assumeDefaultBrowserLocationUsed(); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + void canAddRemoveXpiExtensions() { |
| 35 | + Path extension = InProject.locate(EXT_XPI); |
| 36 | + |
| 37 | + String id = ((HasExtensions) driver).installExtension(extension); |
| 38 | + assertThat( id). isEqualTo( "[email protected]"); |
| 39 | + |
| 40 | + driver.get(pages.blankPage); |
| 41 | + WebElement injected = driver.findElement(By.id("webextensions-selenium-example")); |
| 42 | + assertThat(injected.getText()).isEqualTo("Content injected by webextensions-selenium-example"); |
| 43 | + |
| 44 | + ((HasExtensions) driver).uninstallExtension(id); |
| 45 | + |
| 46 | + driver.navigate().refresh(); |
| 47 | + assertThat(driver.findElements(By.id("webextensions-selenium-example")).size()).isZero(); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void canAddRemoveZipUnSignedExtensions() { |
| 52 | + Path extension = InProject.locate(EXT_UNSIGNED_ZIP); |
| 53 | + |
| 54 | + String id = ((HasExtensions) driver).installExtension(extension, true); |
| 55 | + assertThat( id). isEqualTo( "[email protected]"); |
| 56 | + |
| 57 | + driver.get(pages.blankPage); |
| 58 | + WebElement injected = driver.findElement(By.id("webextensions-selenium-example")); |
| 59 | + assertThat(injected.getText()).isEqualTo("Content injected by webextensions-selenium-example"); |
| 60 | + |
| 61 | + ((HasExtensions) driver).uninstallExtension(id); |
| 62 | + |
| 63 | + driver.navigate().refresh(); |
| 64 | + assertThat(driver.findElements(By.id("webextensions-selenium-example")).size()).isZero(); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + void canAddRemoveZipSignedExtensions() { |
| 69 | + Path extension = InProject.locate(EXT_SIGNED_ZIP); |
| 70 | + |
| 71 | + String id = ((HasExtensions) driver).installExtension(extension); |
| 72 | + assertThat( id). isEqualTo( "[email protected]"); |
| 73 | + |
| 74 | + driver.get(pages.blankPage); |
| 75 | + WebElement injected = driver.findElement(By.id("webextensions-selenium-example")); |
| 76 | + assertThat(injected.getText()).isEqualTo("Content injected by webextensions-selenium-example"); |
| 77 | + |
| 78 | + ((HasExtensions) driver).uninstallExtension(id); |
| 79 | + |
| 80 | + driver.navigate().refresh(); |
| 81 | + assertThat(driver.findElements(By.id("webextensions-selenium-example")).size()).isZero(); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + void canAddRemoveUnsignedExtensionsDirectory() { |
| 86 | + Path extension = InProject.locate(EXT_UNSIGNED_DIR); |
| 87 | + |
| 88 | + String id = ((HasExtensions) driver).installExtension(extension, true); |
| 89 | + assertThat( id). isEqualTo( "[email protected]"); |
| 90 | + |
| 91 | + driver.get(pages.blankPage); |
| 92 | + WebElement injected = driver.findElement(By.id("webextensions-selenium-example")); |
| 93 | + assertThat(injected.getText()).isEqualTo("Content injected by webextensions-selenium-example"); |
| 94 | + |
| 95 | + ((HasExtensions) driver).uninstallExtension(id); |
| 96 | + |
| 97 | + driver.navigate().refresh(); |
| 98 | + assertThat(driver.findElements(By.id("webextensions-selenium-example")).size()).isZero(); |
| 99 | + } |
| 100 | + |
| 101 | + @Test |
| 102 | + void canAddRemoveSignedExtensionsDirectory() { |
| 103 | + Path extension = InProject.locate(EXT_SIGNED_DIR); |
| 104 | + |
| 105 | + String id = ((HasExtensions) driver).installExtension(extension); |
| 106 | + assertThat( id). isEqualTo( "[email protected]"); |
| 107 | + |
| 108 | + driver.get(pages.blankPage); |
| 109 | + WebElement injected = driver.findElement(By.id("webextensions-selenium-example")); |
| 110 | + assertThat(injected.getText()).isEqualTo("Content injected by webextensions-selenium-example"); |
| 111 | + |
| 112 | + ((HasExtensions) driver).uninstallExtension(id); |
| 113 | + |
| 114 | + driver.navigate().refresh(); |
| 115 | + assertThat(driver.findElements(By.id("webextensions-selenium-example")).size()).isZero(); |
| 116 | + } |
| 117 | +} |
0 commit comments