Post on 16-Jul-2015
transcript
5/13/2018 Android WebDriver Example (27 Jan 2011) - slidepdf.com
http://slidepdf.com/reader/full/android-webdriver-example-27-jan-2011 1/4
Android WebDriver Example
Part of the Android Test Automation Series
Julian Harty
27th
January 2011
This documentation includes material from http://code.google.com/p/selenium/wiki/AndroidDriver
Configuring the AndroidDriver
There are several steps required to prepare the android device or emulator, the environment and
the computer. These include:
Installing android-server.apk (the actual filename may differ e.g. if you use a prebuilt version
it will include the release name).
If you want to use an emulator, we currently recommend using one with Android 2.2
installed. The server doesn’t support earlier versions any more (it used to but limitations
with the platform e.g. lack of support for XPath meant the project team have chosen to
target a minimum of 2.2). There’s currently an issue with the Java-to-JavaScript bridge in
version 2.3 of the emulator, so again we don’t recommend using it currently.)
Configuring port forwarding so your tests can communicate with the device or running
instance of the emulator.
Starting the WebDriver Server on the Android emulator (or on a device).
Here are some screenshots of starting the WebDriver instance in an emulator.
5/13/2018 Android WebDriver Example (27 Jan 2011) - slidepdf.com
http://slidepdf.com/reader/full/android-webdriver-example-27-jan-2011 2/4
The following screen is shown once you start WebDriver
5/13/2018 Android WebDriver Example (27 Jan 2011) - slidepdf.com
http://slidepdf.com/reader/full/android-webdriver-example-27-jan-2011 3/4
You may briefly notice a ‘Toast’ message saying “Jetty started”. This disappears after a few seconds.
Jetty is an ‘embedded’ web server used by WebDriver’s Android Server.
Tips and Traps
The Android Server is designed to run on devices with Android 2.2 or higher installed. Thereis currently an issue with the Java to JavaScript bridge in the 2.3 emulator which prevents
the Android Driver from working reliably, use AVDs with version 2.2 of Android until the
issue is addressed. (I don’t have a reference to an open issue to track the problem)
adb forward tcp:8080 tcp:8080 doesn’t provide any visual feedback. If you switch
between devices and /or emulator instances and your tests fail with a network error, kill and
restart adb. adb kill-server followed by adb start-server
Configuring your eclipse project
You will need to include the various jar files from the selenium project in order for your tests to use
‘RemoteWebdriver’. The AndroidDriver implements the RemoteWebdriver protocol. You candownload a zip file from the selenium project site
http://code.google.com/p/selenium/downloads/list e.g. selenium-java-2.0b1.zip currently. This file
needs to be unzipped, which will unpack to 2 selenium jar files (the code and the javadoc
documentation) and a series of 27 other jar files. All these files need to be added to the build path in
your eclipse project. I suggest copying all the files into a common libs folder for your project.
Start and run you WebDriver test(s)
There is some example code on the AndroidDriver wiki page
http://code.google.com/p/selenium/wiki/AndroidDriver this code is also available on the mwta
project site http://code.google.com/p/mwta/source/checkout in the
richinternetsites/mobilewebdriver folder.
http://code.google.com/p/mwta/source/browse/trunk/richinternetsites/mobilewebdriver/javatests
/com/example/OneTest.java
The tests will probably take several seconds to start.
Tip: Remember to include the selenium libraries in the build path for the project.
Here’s a screenshot of a successful test.