Automating the Android testing process

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

About this task

The automation process includes the following steps:

Procedure

  1. 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.

    1. Start Rational Test Workbench Eclipse Client.
    2. In the test workbench, click the Display Workbench URL icon Workbench URL and make note of the Workbench URL. You will need the IP address and port from the Workbench URL for the next step.
    3. 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.

  2. 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.
    1. 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.

    2. 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.

  3. 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”
  4. 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.


Feedback