2

I coded my own extension and I want to add it to geckodriver.

The important thing is I need to add it unpacked as I did for chromedriver.

options.addArguments("--load-extension=" + System.getProperty("user.dir") + "/base/chrome-extension");

Is it possible?

If unpacked is not possible, then, can I install it with creating an archive for that?

Ahmet Aziz Beşli
  • 1,280
  • 3
  • 19
  • 38
  • What about https://stackoverflow.com/a/57612283/5097027 – NarendraR Mar 05 '20 at 14:00
  • No, man, I am looking for "unpacked" – Ahmet Aziz Beşli Mar 05 '20 at 14:01
  • 1
    I found your question trying to find out how to do this with the `selenium-webdriver` JavaScript API. The easiest way seems to be using Mozilla's tool https://github.com/mozilla/web-ext. You can also use that tool to sign your extension when you're ready to publish. Good luck, and please let us know if you found a solution! – Sean May 25 '20 at 04:38
  • We were happily using `web-ext sign` to create XPI files for use with wdio until a Mozilla reviewer wanted to review one. This is now their policy as they can't tell whether you're signing it to test or to supply to real users. We can't risk having to go through the review rigmarole every time we make a test build so I too want to load our extension unsigned. `{ services: [['firefox-profile', { extensions: ['./dist/qa/firefox'] }]] }` doesn't throw any errors but doesn't load the extension. – Denis Howe Jul 26 '21 at 18:52

1 Answers1

0

For (local) firefox webdrivers, simply use driver.installExtension as mentioned in the docs.

As for remote firefox webdrivers (or Selenium Grid), use Augmenter as mentioned in this issue.

The following is an example of Augmenter provided in this webpage with MIT license:

driver.setFileDetector(new LocalFileDetector());
WebDriver augmentedDriver = new Augmenter().augment(driver);
String id = ((HasExtensions) augmentedDriver).installExtension(Paths.get("src/test/resources/ninja_saucebot-1.0-an+fx.xpi"));

driver.get("https://www.saucedemo.com");
Assertions.assertTrue(driver.findElements(By.className("bot_column2")).size() > 0);
((HasExtensions) augmentedDriver).uninstallExtension(id);

driver.navigate().refresh();
Assertions.assertEquals(0, driver.findElements(By.className("bot_column2")).size());
J3soon
  • 3,013
  • 2
  • 29
  • 49