Getting started‎ > ‎

Android

Dependencies

ChromeDriver server

Binaries for ChromeDriver can be found packaged as zip files for various host platforms on the downloads page.

Supported Apps

ChromeDriver supports running tests on Chrome browser (version 30+) as well as WebView-based apps starting in Android 4.4 (KitKat) that have enabled web debugging and JavaScriptYou can install Chrome app from:

Stable: https://play.google.com/store/apps/details?id=com.android.chrome
Beta: https://play.google.com/store/apps/details?id=com.chrome.beta

Selenium Remote Driver

The standard selenium project remote driver language bindings need to be installed for your language of choice for writing your tests. This driver is available from your friendly local package manager or the selenium project (http://docs.seleniumhq.org/download/). For example, the language bindings for Python can be installed with pip.

$ pip install selenium

Android SDK

The SDK can be downloaded from developer.android.com: http://developer.android.com/sdk/index.html

Device Requirements

As of Chrome version 33, a rooted device is no longer required. If running tests on older versions of Chrome, devices needed to be rooted as ChromeDriver required write access to the /data/local directory to set Chrome's command line arguments.

Running ChromeDriver Server

1. Start the Android SDK's Android Debug Bridge (adb) server:

$ adb start-server

2. If testing on Chrome app prior to version 33, ensure adb shell has read/write access to /data/local directory on the device:

$ adb shell su -c chmod 777 /data/local

3. Start the ChromeDriver server. It will print the port it is listening on:

$ ./chromedriver
Started ChromeDriver (v2.0) on port 9515

Android-specific Desired Capabilities

The following capabilities are applicable to both Chrome and WebView apps:
  • androidPackage: The package name of the Chrome or WebView app.
  • androidDeviceSerial: (Optional) The device serial number on which to launch the app (See Multiple Devices section below).
  • androidUseRunningApp: (Optional) Attach to an already-running app instead of launching the app with a clear data directory.
The following capabilities are only applicable to WebView apps.
  • androidActivity: Name of the Activity hosting the WebView.
  • androidProcess: (Optional) Process name of the Activity hosting the WebView (as given by ps). If not given, the process name is assumed to be the same as androidPackage. 

Running a Test

Tests should pass the app’s package name to the server when creating the driver through the capabilitychromeOptions.androidPackage. For example, a minimal Python test looks like this:

from selenium import webdriver
capabilities = {
  'chromeOptions': {
    'androidPackage': 'com.android.chrome',
  }
}
driver = webdriver.Remote('http://localhost:9515', capabilities)
driver.get('http://google.com')
driver.quit()

Alternatively, you can use a ChromeOptions object to specify Android-specific capabilities, and let the WebDriver API to start ChromeDriver for you. For example:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option('androidPackage', 'com.android.chrome')
driver = webdriver.Chrome(chrome_options=options)

Multiple Devices

To use a particular device for a session, specify androidDeviceSerial as a desired capability.

If the serial number is not specified, the server will select an unused device at random to associate with each session. An error will be returned if all devices already have active sessions, so tests should make sure to call quit when finished.

FAQ

If your tests expect to connect to wd/hub, you can add --url-base=wd/hub when launching the server:

$ ./chromedriver --url-base=wd/hub
Comments