Defines the WebDriver client for Firefox. Before using this module, you must download the latest geckodriver release and ensure it can be found on your system PATH.
Each FirefoxDriver instance will be created with an anonymous profile, ensuring browser historys do not share session data (cookies, history, cache, offline storage, etc.)
Customizing the Firefox Profile
The profile used for each WebDriver session may be configured using the Options class. For example, you may install an extension, like Firebug:
const {Builder} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
let options = new firefox.Options()
.addExtensions('/path/to/firebug.xpi')
.setPreference('extensions.firebug.showChromeErrors', true);
let driver = new Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
The Options class may also be used to configure WebDriver based on a pre-existing browser profile:
let profile = '/usr/local/home/bob/.mozilla/firefox/3fgog75h.testing';
let options = new firefox.Options().setProfile(profile);
The FirefoxDriver will never modify a pre-existing profile; instead it will create a copy for it to modify. By extension, there are certain browser preferences that are required for WebDriver to function properly and they will always be overwritten.
Using a Custom Firefox Binary
On Windows and MacOS, the FirefoxDriver will search for Firefox in its default installation location:
- Windows: C:\Program Files and C:\Program Files (x86).
- MacOS: /Applications/Firefox.app
For Linux, Firefox will always be located on the PATH: $(where firefox)
.
You can provide a custom location for Firefox by setting the binary in the Options:setBinary method.
const {Builder} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
let options = new firefox.Options() .setBinary('/my/firefox/install/dir/firefox'); let driver = new Builder() .forBrowser('firefox') .setFirefoxOptions(options) .build();
Remote Testing
You may customize the Firefox binary and profile when running against a remote Selenium server. Your custom profile will be packaged as a zip and transferred to the remote host for use. The profile will be transferred once for each new session. The performance impact should be minimal if you've only configured a few extra browser preferences. If you have a large profile with several extensions, you should consider installing it on the remote host and defining its path via the Options class. Custom binaries are never copied to remote machines and must be referenced by installation path.
const {Builder} = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
let options = new firefox.Options()
.setProfile('/profile/path/on/remote/host')
.setBinary('/install/dir/on/remote/host/firefox');
let driver = new Builder()
.forBrowser('firefox')
.usingServer('http://127.0.0.1:4444/wd/hub')
.setFirefoxOptions(options)
.build();
- Source
Classes
Members
(inner, constant) Context :string
Enum of available command contexts.
Command contexts are specific to Marionette, and may be used with the #context= method. Contexts allow you to direct all subsequent commands to either "content" (default) or "chrome". The latter gives you elevated security permissions.
- string
Name | Type | Description |
---|---|---|
CONTENT | string | |
CHROME | string |
- Source
(inner, constant) ExtensionCommand :string
- string
Name | Type | Description |
---|---|---|
GET_CONTEXT | string | |
SET_CONTEXT | string | |
INSTALL_ADDON | string | |
UNINSTALL_ADDON | string | |
FULL_PAGE_SCREENSHOT | string |
- Source
Methods
(async, inner) buildProfile(templatenullable, extensionsnon-null) → (non-null) {Promise.<string>}
Name | Type | Attributes | Description |
---|---|---|---|
template | string | <nullable> | path to an existing profile to use as a template. |
extensions | Array.<string> | paths to extensions to install in the new profile. |
- Source
a promise for the base64 encoded profile.
- Type:
- Promise.<string>
(inner) configureExecutor(executornon-null)
Configures the given executor with Firefox-specific commands.
Name | Type | Description |
---|---|---|
executor | http. | the executor to configure. |
- Source
(inner) createExecutor(serverUrlnon-null) → (non-null) {command.Executor}
Creates a command executor with support for Marionette's custom commands.
Name | Type | Description |
---|---|---|
serverUrl | Promise.<string> | The server's URL. |
- Source
The new command executor.
- Type:
- command.
Executor
(inner) findInProgramFiles(file) → (non-null) {Promise.<?string>}
Name | Type | Description |
---|---|---|
file | string | Path to the file to find, relative to the program files root. |
- Source
A promise for the located executable. The promise will resolve to {@code null} if Firefox was not found.
- Type:
- Promise.<?string>
(async, inner) installExtension(extension, dir) → (non-null) {Promise.<string>}
Installs an extension to the given directory.
Name | Type | Description |
---|---|---|
extension | string | Path to the xpi extension file to install. |
dir | string | Path to the directory to install the extension in. |
- Source
A promise for the add-on ID once installed.
- Type:
- Promise.<string>