You can automate the process of testing Android apps by
using the command line interface with the Android Debug Bridge (adb)
utility and a command-line tool, such as curl.
You can then combine the command line statements into scripts and
batch files.
Before you begin
- Install IBM® Rational® Test Workbench Mobile Test Edition and ensure that the Extension for Mobile
is selected. For details, see Installing
the product software.
- Download and install the Android SDK on the computer that the test workbench is installed on.
At minimum be sure to install the Android SDK Tools, Android SDK Platform-tools,
Android SDK Build-tools, and the Android Debug Bridge (adb)
utility if these are not already installed. The current download page
of the Android SDK is at Get
the Android SDK but the location could change in the future.
- If you are working on a Windows computer,
download curl from http://curl.haxx.se/. curl is
a command line tool for transferring data with URL syntax and is needed
here to automate the instrumentation process. curl is
included by default on most Linux distributions.
- To test on Android emulators, set up one or more AVD (Android
Virtual Device) configurations. For details, see Using the Emulator. This article also describes
ways to improve emulator performance through hardware acceleration.
- To test on Android devices, go to Settings and enable USB debugging.
Then, connect the Android device with a USB cable to the computer
that is running the test workbench.
Because some mobile devices require a specific USB driver, it might
be necessary to go to the Web site of the device vendor to download
and install the USB driver for the device. For details, see Installing the mobile test client for Android with adb.
- Record the test scripts for the application under test (AUT).
The test recording process cannot be automated. See Recording tests from the Android mobile test client for details.
About this task
The automation process includes the following steps:
- Instrumenting the latest release of an app
- Installing the latest release of the app on an Android device
or emulator
- Installing the mobile test client and
starting it in passive mode
- Running the test from the command line interface
Procedure
- Instrument the latest release of the AUT.
You can instrument Android apps manually by uploading the
application from a mobile device or emulator to the test workbench or by clicking
the Add application to list button from within
the test workbench. To
automate the process, use a tool such as curl.
- Start Rational Test Workbench Eclipse
Client.
- In the test workbench,
click the Display Workbench URL icon
and
make note of the Workbench URL. You will need the IP address and port
from the Workbench URL for the next step.
- Run the following command line to instrument the AUT:
curl -F "appfile=@MyApp.apk"
-F "appdescription=My App Description"
http://Workbench-URL:port/moeb/service/com.ibm.rational.test.lt.core.moeb.services.buildchain.IBuildChainService/?action=upload
For
example:
curl -F "appfile=@MyExpenses.apk"
-F "appdescription=Expense report app"
http://192.0.2.24:7878/moeb/service/com.ibm.rational.test.lt.core.moeb.services.buildchain.IBuildChainService/?action=upload
This step results in three new .apk files:
- R-original apk name.apk -
Playback-ready application
- T-original apk name.apk -
Test engine for the application
- I-original apk name.apk -
Recording-ready application
For details about .apk files, instrumentation,
and the Android build process, see Android testing overview.
- Use adb to install
the latest release of the AUT on an Android device or emulator. Both
the playback-ready .apk file and the test engine .apk file
must be installed. The adb utility is typically
installed at Android-SDK-install-location\sdk\platform-tools.
- Locate the playback-ready .apk file
and the test engine .apk file at the following
location in your Eclipse workspace:
your-workspace/.metadata/.plugins/com.ibm.rational.test.lt.models.behavior.moeb/builds/AUT-uid/R-original-apk-name.apk
where AUT-uid is
the folder name of the last modified subfolder of the builds folder.
Typically, the AUT-uid is a long hexadecimal
number.
Example:
C:\workspaces\rtw86\.metadata\.plugins\com.ibm.rational.test.lt.models.behavior.moeb\builds\b01714617a0a34788898e05c9696e0bf\R-expenses.apk
You
can find the test engine app at the same location. Just replace the R prefix
with T.
- Run the following commands from the command line:
adb install -r Workspace/.metadata/.plugins/com.ibm.rational.test.lt.models.behavior.moeb/builds//AUT-uid/R-AUT-name.apk
adb install -r Workspace/.metadata/.plugins/com.ibm.rational.test.lt.models.behavior.moeb/builds//AUT-uid/T-AUT-name.apk
To
install the AUT on multiple devices or emulators, use the -s (Serial
Number) option, for example:
adb install -s emulator-5556 -r
C:\workspaces\rtw86\.metadata\.plugins\com.ibm.rational.test.lt.models.behavior.moeb\builds\b01714617a0a34788898e05c9696e0bf\R-expenses.apk
adb install -s emulator-5558 -r
C:\workspaces\rtw86\.metadata\.plugins\com.ibm.rational.test.lt.models.behavior.moeb\builds\b01714617a0a34788898e05c9696e0bf\T-expenses.apk
For details, see Directing commands to a specific emulator or device.
- Install the mobile test client and start it
in passive mode. Passive mode allows text execution to be controlled
by a script or batch file in the test workbench.
Run
the following adb commands to uninstall an existing
version of the mobile test client,
reinstall a newer version of the client, and set the client to passive
mode.
adb uninstall com.ibm.rational.test.mobile.android.client.ui
adb install "Eclipse client path/com.ibm.rational.test.mobile.android.client.ui-release.apk"
adb shell am start
-n com.ibm.rational.test.mobile.android.client.ui/.MainActivity -e workbench_url "Workbench-Url" --ez passive_mode “true”
For
example:
adb uninstall com.ibm.rational.test.mobile.android.client.ui
adb install "C:\Program Files\IBM\IBMIMShared\com.ibm.rational.test.mobile.android.client.ui-release.apk"
adb shell am start
-n com.ibm.rational.test.mobile.android.client.ui/.MainActivity -e workbench_url "9.44.55.666:7878" --ez passive_mode “true”
- Run a test in command line mode.
Now
you can run a test. For details about running a test or schedule in
command line mode, see Running
a test or schedule from the command line.
Note: You cannot
run a test from the command line on Mac OS X.
By default,
the test workbench selects
the first connected device that best fits the test execution requirements
(Android OS and Android API). To run the test on one or more specific
devices, use the adb -s device ID option.
To find the Device ID, open the Mobile Devices editor in the test workbench, select a device,
and look for the ID in Detailed Properties.
You can also use
a variable to select a specific device. For details, see Defining a variable to run a test with a selected mobile device.
All test scripts are
linked to a specific version of the AUT. If you upload a new version
of the AUT, you should always run the test on the newest version of
the AUT. For details, see Defining a variable in a test to run the latest version of an application.