Firefox Specific Commands
The FirefoxDriver exposes some specific commands, such as for setting context to run "privileged" javascript code or for working with addons. These are now available on in Nightwatch directly, on the firefox
namespace.
browser.firefox:
More info:
Customizing the Firefox Profile
Each Firefox WebDriver instance will be created with an anonymous profile, ensuring browser historys do not share session data (cookies, history, cache, offline storage, etc.).
The profile used for each WebDriver session may be configured using the Options class from Selenium. Nightwatch 2 fully supports options objects created with the selenium-webdriver
library.
Installing a Firefox extension:
Let's say you need to install an extension, called Firebug. In your nightwatch.conf.js
, you may use the Options class to configure the WebDriver session like so:
const firefox = require('selenium-webdriver/firefox');
const options = new firefox.Options()
.addExtensions('../../../path/to/firebug.xpi')
.setPreference('extensions.firebug.showChromeErrors', true);
module.exports = {
src_folders: ['tests'],
test_settings: {
default: {
browserName: 'firefox',
desiredCapabilities: options
}
}
};
Or as a function:
module.exports = {
src_folders: ['tests'],
test_settings: {
default: {
browserName: 'firefox',
desiredCapabilities() {
const firefox = require('selenium-webdriver/firefox');
const options = new firefox.Options()
.addExtensions('../../../path/to/firebug.xpi')
.setPreference('extensions.firebug.showChromeErrors', true);
return options;
}
}
}
};