4

I'm trying to test my firefox webextension but firefox refuses to install it because it doesn't have the install.rdf file. But that file is not used anymore by webextensions.

const firefox = require('selenium-webdriver/firefox');
const webdriver = require('selenium-webdriver');
require('geckodriver');

let profile = new firefox.Profile();
profile.addExtension(process.cwd() + '/build/firefox/');
profile.setPreference('extensions.firebug.showChromeErrors', true);


let options = new firefox.Options().setProfile(profile);

let _driver = new webdriver.Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();

Error: ENOENT: no such file or directory, open '/dev/webext/build/firefox/install.rdf'

Is there a setting that I need to enable to tell it it's a webextension?

Jérémie Bertrand
  • 3,025
  • 3
  • 44
  • 53
Cornwell
  • 3,304
  • 7
  • 51
  • 84

2 Answers2

4

The WebExtension API is not yet supported by Selenium v3.4.0 . The method Profile::addExtension only works for a legacy addon where install.rdf is present at the root.

To test a web extension, you can either use a profile where the extension is already installed, or you can implement the custom command available with GeckoDriver since v0.17.0:

var webdriver = require('selenium-webdriver');
var Command = require('selenium-webdriver/lib/command').Command;


function installWebExt(driver, extension) { 
  let cmd = new Command('moz-install-web-ext')
    .setParameter('path', path.resolve(extension))
    .setParameter('temporary', true);

  driver.getExecutor()
    .defineCommand(cmd.getName(), 'POST', '/session/:sessionId/moz/addon/install');

  return driver.schedule(cmd, 'installWebExt(' + extension + ')');
}


var driver = new webdriver.Builder()
  .forBrowser('firefox')
  .build();

installWebExt(driver, "C:\\temp\\extension.zip");
Florent B.
  • 41,537
  • 7
  • 86
  • 101
  • Thanks! That works!. One question though, is it possible to retrieve the extension internal UUID ? So I could then access the extension's popup – Cornwell Jul 12 '17 at 07:37
  • Check the value returned by `installWebExt`, it could be the UUID: `installWebExt(...).then(id => ...)` – Florent B. Jul 12 '17 at 08:06
  • unfortunately it's the extension's id as it is in the manifest, so it cannot be used for that. But I think I can make some ugly hack to retrieve it from the `about:debugging#addons` page. Thanks again! – Cornwell Jul 12 '17 at 08:45
1

This is an issue with FirefoxDriver. This issue is already logged in both SeleniumHQ/selenium#4184 and mozilla/geckodriver#759

GeckoDriver says that

A workaround for the time being would be to use the add-on endpoints geckodriver 0.17.0 provides to get an extension installed from the local disk.

https://github.com/mozilla/geckodriver/blob/release/src/marionette.rs#L66

So you have to use the geckodriver endpoints to do that. I have already mentioned on how to use the endpoints here

Madhan
  • 5,750
  • 4
  • 28
  • 61
  • Thanks. Unfortunately it doesn't seem that the `getAddressOfRemoteServer ` is available so I'm unable to get the PORT to connect to – Cornwell Jul 10 '17 at 10:39