Friday, 2 January 2015

Helper test suite.

Helper test suite is a special test suite which will contain helper/utility classes for your UIautomator test cases. Helper test suite cannot have UIautomator test cases.  

Lets go through the steps to create Helper test suite,

1. Right click on TestCase Browser > New > Test Suite. A test suite creation wizard will be opened as shown in Fig 1.

2. Enter test suite name, description and check "is this a helper test suite?" check box as shown in Fig 1.

Fig 1: Creating helper test suite.

3. Click finish. A helper test suite will be created as shown in the Fig 2.

Fig 2: Created helper test suite.

Now you can create helper/utility classes for your test cases in the helper suite. Procedure to create classes in helper suite is similar to creating a normal test case[ refer create-and-execute-uiautomator-test-case]. The only difference being the created class will not be a UIautomator test case (Fig 3). Further, as the classes in the helper suite are not UIautomator test cases, these classes cannot be added for execution in the Test Runner view. UIautomator-bot takes care of finding helper classes of a test case during execution.

Fig 3: Helper/Utility class
Following is the generated helper class You can create any number of utility methods. By default few static methods are created, you can delete these methods if you are not going to use them. It is recommended you make any new method as static for ease of use in your test case.

package Test123.Helper_Test_Suite_Example;


import android.os.Build;
import android.util.Log;
import static Test123.BBAT_Utility.BBATUtility.*;

This is a utility class for test case

NOTE:1.This class is a utility/helper class for your test cases.
            2.This class cannot have any test cases.<br>
            3.Do not change the class name.
            4.You can create as many methods you want.
public class TestCaseUtility {  

    private static String TAG = "TestCaseUtility";
    /** This method returns a UiDevice instance.
    public static UiDevice getDevice(){
        return UiDevice.getInstance();
    This is an example method to explain the usage.
    You can call this method from your test case as follows
    public static void helper_example_method(){
    This method can be used to do some setup before the test case execution.
    public static void preTestCaseRun(){
    This method can be used to do some cleanup after the test case execution.
    public static void postTestCaseRun(){

Following is an example of UIautomator test case to show usage of helper class created earlier.

package Test123.TesCase_Suite;


import Test123.Helper_Test_Suite_Example.TestCaseUtility;
import android.os.Build;
import android.util.Log;
import static Test123.BBAT_Utility.BBATUtility.*;

  This is a sample testcase to show the usage of helper/utility methods.

NOTE:1.This class can contain only one test case.
     2.Do not change the class name.
public class HelperUsageExample extends UiAutomatorTestCase {   

    private static String TAG = "HelperUsageExample";
        All your test code will go here
        NOTE: Do not change the method signature
    public void test() throws UiObjectNotFoundException {  
            System.out.println("testcase execution started");
            System.out.println("testcase execution completed");

>>Create and execute Uiautomator test cases.

Monday, 25 August 2014

What is UIautomator-bot ?

UIautomator-bot is a automation tool for android UIautomator. The important features of the UIautomator-bot is listed below.
  1. Simultaneous execution of test cases on more than one device.
  2. It captures device and Uiautomator logs during test case execution.
  3. Screen shot capture.
  4. Each test case execution artifacts are persisted, this allows user to debug/analyze the test case execution later. 
  5. Provides simple and intuitive way to manage test cases.
  6. Memory and CPU usage of application during execution.

UIautomator-bot  tool is divided in to three perspectives as explained below:
  • Developer
  • Tester
  • History

Developer perspective is where all the development work happens.
This perspective provides a test case browser view for test case management, a devices view that lists all the devices connected to the machine and an eclipse based java editor to write and edit UIautomator test cases. Further, the UIautomator viewer is integrated with the tool for ease of use.

Fig 1: Developer perspective.


Tester perspective is where all the execution action happens. This perspective has a test runner view where the tester can add the test cases and devices for execution. The execution status of test case on each device is dynamically updated during execution. It also has an option to abort the execution.

Fig 2: Tester perspective.


Each round of execution is categorized as a Test Run in UIautomator-bot  these test runs are listed in the History perspective. Each test case execution's device and UIautomator logs are listed in their corresponding device and UIautomator log views. Screen shot views lists down all the screen shots taken by the test case during execution. Memory and CPU  usage view displays the   memory  and CPU consumed during test case execution.

Fig 3: History perspective.

Wednesday, 20 August 2014

Create and Execute UIautomator test case with UIautomator-bot

At the end of this article you will be able to create and execute UIautomator test case with UIautomator-bot. This article will not go through android UIautomator APIs, for android UIautomator APIs refer this link.

UIautomator-bot defines a new way to create, organize and execute UIautomator test cases. In UIautomator-bot,  every Test Case belongs to a Test Suite and every Test Suite belongs to a Test Project. Therefore, you need a Test Project and a Test Suite before creating a test case.

Create Test Project.

Right click in the Test Case Browser view> New > Test Project. This will open a  Test Project creation wizard as shown in Fig 1.

Fig 1: Create Test Project wizard.

Select  appropriate API level. The UIautomator.jar and Android.jar is automatically resolved  by UIautomator-bot based on the selected API level .

Provide a valid name and brief description about the project. Enter the package name of APK under test, this is optional and is only required if you want to track CPU and Memory usage of the application while testing.

Create Test Suite.

Right click on Test Project created in previous step > New > Test Suite. This will open a Test Suite creation wizard as shown in Fig 2.

Fig 2: Test Suite Creation Wizard.

Provide a test suite name and brief description and click finish. Ignore the helper test suite check box for now.

Create Test case.

Right click on Test Suite created in previous step > New > Test Case. This will open a Test Case creation wizard as shown in Fig 3.

Fig 3: Test Case Creation Wizard.

Provide name and description of the Test Case. Test case name should follow Java naming convention. New Test case is opened in a java editor as shown in Fig 4.

Fig 4: Test Case editor.

UIautomator viewer can be opened from UIautomator-bot by clicking the toolbar button in the Connected Devices view.


Connect one or more android device (4.1+) to the machine via USB. The connected devices will be listed in the Connected Devices view as shown in Fig 5:

Fig 5: Device Connected.

To execute test case(s) switch to Tester perspective.

1. Drag and drop test case(s) to be executed in Test Runner view.
2. Drag and drop connected devices in to Test Devices view.
3. Click Execute button in the top right corner of the Test Runner View.

The execution of the test cases will start on all the selected devices simultaneously.

Fig 6: Tester Perspective.


Once the execution is complete switch to History perspective to see detailed results of test case execution. History perspective shows the device logs, UIautomator logs, screenshots , time taken and CPU and memory usage( if package name is defined).

Fig 7: History Perspective.

Installing UIautomator-bot.

UIautomator-bot is an open source automation tool for android UIautomator. This article will explain  installation of Uiautomator-bot .

Pre - requisites :

1. Requires JDK 1.5 or above .
2. Latest  Android SDK  download it from here.

Installation :

1.  Download UIautomator-bot from here.
2.  Extract the downloaded zip file in some directory.
3. Run(double click) the uiautomator-bot executable and voila UIautomator-bot is installed and running.

Fig 1: Installed UIautomator-bot.
Now before you proceed with creating and testing your android application you need to configure  android SDK path and UIautomator-bot test cases directory. 

Go to  File > Configure to update the android SDK path and the test case directory.

Configure Uiautomator-bot
Fig 2: Configure android SDK and test cases directory.

NoteUIautomator-bot automatically identifies the android SDK installed on the machine.

To create and execute test cases in UIautomator-bot follow this link .