1. Install the Android SDK
Download the Android SDK at the following URL
Http://developer.android.com/sdk/index.html
2. Create an Android virtual device
Jie Baogang Download the SDK package, go to the Tools directory, and launch the AVD Manager (Android Virtual Device Manager)
$ CD Adt-bundle-mac-x86_64-20130917/sdk/tools
$./android AVD
3. Create a new Android virtual device
Click New on the AVD manager to create a new Android virtual device. After the new Android virtual device is created, you can start it. Refer to the Android Developer website for specific steps
4. Set up Android virtual device
Two ways to run Android Webdriver, one based on Remotewebdriver Server and the other based on the Android Test Framework, they have the following advantages and disadvantages:
Remotewebdriver Server |
Android Test Framework |
A programming language that can support bindings with any selenium |
Use Java only |
Slow to run because each command is an HTTP-based RPC method |
Run fast because the test is directly on the simulator or on the real device |
More portability, testing many different browsers with the same set of code |
Already using the Android test Framework and are not going to test other browsers with the same set of code |
This article focuses on the Remotewebdriver server approach, which includes server-side and client 2-part
1) Client
Typically refers to a test case code that uses a JUnit or TestNG organization that can be run directly in the IDE or run as a command line
2) server-side
An application that runs on an Android device and contains an HTTP server
When you run the test case, each webdriver command for the client sends a RESTful HTTP request-Path server with the JSON protocol. The remote HTTP server forwards the request sent by the client to Android Webdriver and sends the result back to the clients. Specific JSON protocol specification see: Http://code.goole.com/p/selenium/wiki/JsonWireProtocol
5. Install and set up Android webdriver Server
1) Regardless of the Android emulator or Android real device, there is a serial number serial ID, the following command first get the emulator or device serial ID, in this case the serial number is f14c451c
$ CD adt-bundle-mac-x86_64-20130917/sdk/platform-tools/
$./ADB Devices
List of devices attached
F14C451C Device
2) Download apk file for Android server: https://code.google.com/p/selenium/downloads/list
3) Before installing the android-server.apk file to the Android emulator or the real device, make sure that the Android system allows the installation of applications that are not downloaded from the Android official market, and install the command:
$ ./adb-s<serialid>-E install-r android-server.apk
In conjunction with the specific serial number of this example and the version of Android Server, the command execution demerit is as follows:
$./adb-s f14c451c-e Install-r android-server-2.32.0.apk
...
Success
4) There are 2 ways to start the Android Webdriver application, one is to start from the Android emulator or the device's UI, and the other is to start from the command, as follows:
$ ./adb-s<serialid> Shell am start-a android.intent.action.main-n org.openqa.selenium.android.app/. Mainactivity
In combination with the specific serial number, the command execution results are as follows:
$./adb-sf14c451c Shell am start-a android.intent.action.main-n org.openqa.selenium.android.app/. Mainactivity
Starting:intent{act = Android.intent.action.MAIN cmp = org.openqa.selenium.android.app/. Mainactivity}
5) If you need to enter debug mode, you can open this option with the following command:
$ ./adb-s<serialid> Shell am start-a android.intent.action.main-n org.openqa.selenium.android.app/. Mainactivity-e Debug True
In combination with the specific serial number, the command execution results are as follows:
$./adb-s sf14c451c Shell am start-a android.intent.action.main-n org.openqa.selenium.android.app/. Mainactivity-e Debug True
Starting:intent{act = Android.intent.action.MAIN cmp = org.openqa.selenium.android.app/. Mainactivity (has extras)}
6) Set Port forwarding rules
$ ./adb-s<serialid> Forward tcp:8080 tcp:8080
In conjunction with this example, setting the local port to 8888, the command execution results are as follows:
$./adb-s sf14c451c forward tcp:8888 tcp:8080
This completes the installation and setup of Android Webdriver Server, and then you can see the status of the test code interacting with Android Webdriver server from the following address on this computer:
Http://localhost:8888/wd/hub/status
The following methods can be checked to confirm that Android Webdriver server is installed and set up correctly:
1) http://localhost:8888/wd/hub/status in browser to see if port forwarding is successful, {status:0} is displayed normally
2) Use the telnet command: telnet localhost 8888
3) Use the Curl command: $ curl Http://localhost:8888/wb/hub/status
4) Use the wget command: $ wget http://localhost:8888/wb/hub/status
Next you can run test cases, and there are a few places to be aware of:
1) Ensure that the "USB debug", "Wake-up status", and "Allow impersonation Places" in developer options on Android phones are turned on
2) Make sure that USB data store is turned off on your Android phone, or it will cause an sdcard error to occur when you execute the test case.
Test Case Examples:
Import Org.openqa.selenium.android.AndroidDriver;
...
Start Android Webdriver and set the forwarding address of the message to the following address 8888 port
Webdriver Driver = new Androiddriver ("Http://localhost:8888/wd/hub");
Driver.get ("www.1.com");
String URL = driver.getcurrenturl ();
Driver.close ();
Build Android Webdriver Environment