ChromeDriver
Overview
Run your Nightwatch.js tests in Chrome using ChromeDriver.
In this guide, you will learn about:
- Downloading ChromeDriver
- Supported Chrome capabilities
- Supported Chrome preferences
- Working with Chrome in Docker
Download
Step 1. Download ChromeDriver - Download the latest version of the ChromeDriver for your platform from the Downloads page.
Step 2. Configure the path - Set the location of the ChromeDriver binary under the webdriver
object in your nightwatch.json
file as follows:
"webdriver" : {
"server_path" : "/path/to/chromedriver"
}
Supported Chrome Capabilities
The following table provides a list of all the Chrome-specific desired capabilities, which are all under the ChromeOptions dictionary.
Name | Type | Description |
---|---|---|
args |
array of strings | List of command-line arguments to use when starting Chrome. Arguments with an associated value should be separated by a '=' sign (e.g., ["start-maximized", "user-data-dir=/tmp/temp_profile"] ). |
binary |
string | Path to the Chrome executable to use (on Mac OS X, this should be the actual binary, not just the app. e.g., '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome') |
extensions |
array of strings | A list of Chrome extensions to install on startup. Each item in the list should be a base-64 encoded packed Chrome extension (.crx) |
Nightwatch supports all arguments and capabilities that ChromeDriver provides.
Check out the official ChromeDriver documentation to learn more about these capabilities.
You can refer to this list of command line switches that you can pass as args
to the chromeOptions
key under your desiredCapabilities
key in your nightwatch.json
file as follows:
"desiredCapabilities" : {
"browserName" : "chrome",
"javascriptEnabled" : true,
"acceptSslCerts" : true,
"chromeOptions" : {
"args" : ["start-fullscreen"]
}
}
Supported User Preferences
Apart from the command line switches that you set using the args
key, you can also pass the Chrome profile preferences using the prefs
key.
The following code snippet shows how to set the preferences if you want to disable the browser's password manager feature in the nightwatch.json
file:
"desiredCapabilities" : {
"browserName" : "chrome",
"javascriptEnabled" : true,
"acceptSslCerts" : true,
"chromeOptions" : {
"prefs" : {
"credentials_enable_service" : false,
"profile.password_manager_enabled" : false
}
}
}
Using Chrome running in a Docker container
If your tests require a Chrome instance running inside a Docker container, ensure that you add the --no-sandbox
value to the args
object to access the Chrome binary from the docker container.
"chromeOptions" : {
"args" : ["--no-sandbox"]
}