module selenium-webdriver/chrome
Defines a WebDriver client for the Chrome
web browser. Before using this module, you must download the latest
ChromeDriver release and ensure it can be found on your system PATH.
There are three primary classes exported by this module:
-
ServiceBuilder: configures the
remote.DriverService
that manages the ChromeDriver child process.
-
Options: defines configuration options for each new Chrome
session, such as which proxy to use,
what extensions to install, or
what command-line switches to use when
starting the browser.
-
Driver: the WebDriver client; each new instance will control
a unique browser session with a clean user profile (unless otherwise
configured through the Options
class).
Customizing the ChromeDriver Server
By default, every Chrome session will use a single driver service, which is
started the first time a Driver
instance is created and terminated
when this process exits. The default service will inherit its environment
from the current process and direct all output to /dev/null. You may obtain
a handle to this default service using
getDefaultService()
and change its configuration
with setDefaultService()
.
You may also create a Driver
with its own driver service. This is
useful if you need to capture the server's log output for a specific session:
var chrome = require('selenium-webdriver/chrome');
var service = new chrome.ServiceBuilder()
.loggingTo('/my/log/file.txt')
.enableVerboseLogging()
.build();
var options = new chrome.Options();
// configure browser options ...
var driver = new chrome.Driver(options, service);
Users should only instantiate the Driver
class directly when they
need a custom driver service configuration (as shown above). For normal
operation, users should start Chrome using the
selenium-webdriver.Builder
.
Working with Android
The ChromeDriver supports running tests on the Chrome browser as
well as WebView apps starting in Android 4.4 (KitKat). In order to
work with Android, you must first start the adb
adb start-server
By default, adb will start on port 5037. You may change this port, but this
will require configuring a custom server that will connect
to adb on the correct port:
var service = new chrome.ServiceBuilder()
.setAdbPort(1234)
build();
// etc.
The ChromeDriver may be configured to launch Chrome on Android using
Options#androidChrome()
:
var driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options().androidChrome())
.build();
Alternatively, you can configure the ChromeDriver to launch an app with a
Chrome-WebView by setting the androidActivity option:
var driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options()
.androidPackage('com.example')
.androidActivity('com.example.Activity'))
.build();
[Refer to the ChromeDriver site] for more information on using the
ChromeDriver with Android.
Functions
getDefaultService()code »
Returns the default ChromeDriver service. If such a service has not been
configured, one will be constructed using the default configuration for
a ChromeDriver executable found on the system PATH.
setDefaultService(service)code »
Sets the default service to use for new ChromeDriver instances.
Throws
Error
If the default service is currently running.
Types
- Driver
Creates a new WebDriver client for Chrome.
- Options
Class for managing ChromeDriver specific options.
- ServiceBuilder
Creates selenium-webdriver/remote.DriverService
instances that manage
a ChromeDriver
server in a child process.