firefoxOptions
Themoz:firefoxOptions
capability is a namespaced set ofcapabilities specific toFirefox. It is used to control thebehavior of Firefox and can be used as a member ofalwaysMatch
or as a member of one of thefirstMatch
entries.
It is used to define options which control how Firefox gets started and run.
moz:firefoxOptions
is a JSON Object which may contain any of the following fields:
binary
(string)
Absolute path to the custom Firefox binary to use.
On macOS you may either give the path to the application bundle, i.e.,/Applications/Firefox.app
, or theabsolute path to the executable binary inside this bundle, for example/Applications/Firefox.app/Contents/MacOS/firefox-bin
.
geckodriver will attempt to deduce the default location of Firefox on the current system if left undefined. Thedefault locations of Firefox are:
System | Default location |
---|---|
macOS |
|
Linux BSD | First % which firefox/usr/bin/firefox |
Windows | From the Window system registry:
|
args
(array of strings)
Command line arguments to pass to the Firefox binary. These must include the leading dash (-
) whererequired, e.g.,["-headless"]
.
To have geckodriver pick up an existingprofile on the local filesystem, you may pass["-profile", "/path/to/profile"]
. But if a profile has to be transferred to a target machine it isrecommended to use theprofile
entry.
profile
(string)
Base64-encoded ZIP of a profile directory to use for the Firefox instance. This may be used to e.g., installextensions or custom certificates, but for setting custom preferences we recommend using theprefs
(Preferences Object) entry instead.
Profiles are created in the systems temporary folder. This is also where the encoded profile is extracted whenprofile
is provided. By default geckodriver will create a new profile in this location.
The effective profile in use by the WebDriver session is returned to the user in themoz:profile
capability in thenew session response.
To have geckodriver pick up an existing profile on the filesystem, please set theargs
field to{"args": ["-profile", "/path/to/your/profile"]}
. Note that if you use a remote client targeting a serveron a different system, the profile must already exist on the target system.
log
(Log object)
To increase the logging verbosity of geckodriver and Firefox, you may pass alog
object that may look like{"log": {"level": "trace"}}
to include all trace-level logs and above
prefs
(Preferences object)
Map of preference name to preference value, which can be a string, a boolean or an integer.
In this article
Android
Starting with geckodriver 0.26.0 additional capabilities exist if Firefox or an application embeddingGeckoView has to be controlled on Android:
androidPackage
(string, required)
The package name of Firefox, e.g.,org.mozilla.firefox
,org.mozilla.firefox_beta
, ororg.mozilla.fennec
depending on the releasechannel, or the package name of the application embedding GeckoView, e.g.,org.mozilla.geckoview_example
.
androidActivity
(string, optional)
The fully qualified class name of the activity to be launched, e.g.,.GeckoViewActivity
. If notspecified, the package's default activity will be used.
androidDeviceSerial
(string, optional)
The serial number of the device on which to launch the application. If not specified and multiple devices areattached, an error will be returned.
androidIntentArguments
(array of strings, optional)
Arguments to launch the intent with. Under the hood, geckodriver usesAndroid am to start the Android applicationunder test. The given intent arguments are appended to theam start
command. See Android'sspecification for intent arguments fordetails. This allows to control how the application is launched and to include optional extras for enabling anddisabling features. For example, to launch with the view action and a specified URL before navigating as part of atest, include:
{ "androidIntentArguments": [ "-a", "android.intent.action.VIEW", "-d", "https://example.com" ]}
For example, to specify a boolean extra that can be processed withandroid.content.Intent.getBooleanExtra, include:
{ "androidIntentArguments": ["--ez", "customBooleanFlagName", "true"]}
env
(Env object)
Map of environment variable name to environment variable value, both of which must be strings, that will be forwarded to application process running on the Android device.
Log object
A JSON Object that may have any of these fields:
level
(string)
Set the level of verbosity of geckodriver and Firefox. Available levels aretrace
,debug
,config
,info
,warn
,error
, andfatal
. If leftundefined the default isinfo
. The value is treated case-insensitively.
Preferences object
A JSON Object with one entry per preference to set. The preference will be written to theprofile before starting Firefox. A full list of available preferences is available from visiting"about:config" in your Firefox browser. Some of these are documented inthis source file.
An example of a preference object:
{ "dom.ipc.processCount": 8, "javascript.options.showInConsole": false}
Env object
A JSON Object with one entry per environment variable to set. On Desktop, the Firefox under test will launch withgiven variable in its environment. On Android, the GeckoView-based App will have the given variable added to theenv
block in its configuration YAML.
An example of an env object:
{ "MOZ_LOG": "nsHttp:5", "MOZ_LOG_FILE": "/mnt/sdcard/log"}
Example
The following is an example of a fullcapabilities object thatselects a specific Firefox binary to run with a preparedprofile from the filesystem inheadless mode. It also increases the number of IPC processesthrough a preference, turns off chrome errors/warnings in the console, and enables more verbose logging:
{ "capabilities": { "alwaysMatch": { "moz:firefoxOptions": { "binary": "/usr/local/firefox/bin/firefox", "args": ["-headless", "-profile", "/path/to/my/profile"], "prefs": { "dom.ipc.processCount": 8, "javascript.options.showInConsole": false }, "log": { "level": "trace" }, "env": { "MOZ_LOG": "nsHttp:5", "MOZ_LOG_FILE": "/path/to/my/profile/log" } } } }}
Themoz:firefoxOptions
must be placed—as above—insidealwaysMatch
, or in one of thefirstMatch
capabilities objects as seen here:
{ "capabilities": { "firstMatch": [{ "moz:firefoxOptions": {} }] }}
Android
This runs the GeckoView example application as installed on the first Android emulator running on the host machine:
{ "capabilities": { "alwaysMatch": { "moz:firefoxOptions": { "androidPackage": "org.mozilla.geckoview_example", "androidActivity": "org.mozilla.geckoview_example.GeckoView", "androidDeviceSerial": "emulator-5554", "androidIntentArguments": ["-d", "http://example.org"], "env": { "MOZ_LOG": "nsHttp:5", "MOZ_LOG_FILE": "/mnt/sdcard/log" } } } }}