'How to install custom extension to headless Firefox in Linux?

Automated tests with Selenium are awesome, but how to do them on headless Firefox with a pre-installed extension?

I found this for Chrome, but nothing for Firefox

How to install an extension to FF?



Solution 1:[1]

I don't know the language you are using, but if you have the xpi file handy you can install (or rather enable it like this)

this is a javascript way, but all selenium drivers work the same (look for the profile part)

let binary;
switch (channel) {
    case 'nightly':
    binary = new firefox.Binary(firefox.Channel.NIGHTLY);
    break;
    case 'beta':
    binary = new firefox.Binary(firefox.Channel.BETA);
    break;
    default:
    binary = new firefox.Binary(firefox.Channel.RELEASE);
}

binary.addArguments('-headless');

let options = new firefox.Options();
options.setBinary(binary);

let profile = new firefox.Profile();
profile.addExtension(path.join(__dirname, '[email protected]'));
options.setProfile(profile);

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

Solution 2:[2]

now you can install any chrome extension to Firefox. here is the solution. How to install chrome extension to firefox?

Solution 3:[3]

You can install add-on globally via command line using (e.g. on my Ubuntu):

gksudo firefox -install-global-extension "path_to_your.xpi"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Madacol
Solution 2 Atif Hussain
Solution 3 Ond?ej Don?k