How to use UiAutomator to test android native applications


1.    Overview

The Android SDK provides the following tools to support automated, functional UI testing on your application:

  • Uiautomatorviewer– A GUI tool to scan and analyze the UI components of an Android application.
  • Uiautomator– A Java library containing APIs to create customized functional UI tests, and an execution engine to automate and run the tests.

To use these tools, you must have the following versions of the Android development tools installed:


2.    Download and install Android SDK

Step1: Download Android SDK

Get source from:

Step2: Extract this downloaded file into local driver

Step3: Update latest Android SDK

Go Android SDK folder and click on “SDK Manager” and wait to android SDK Manager Window show up:

  • To check Android platform installed:
  • Go to ANDROID_SDK\tool\
  • Open windows command line and type: android list target

3.    Setup Environment

4.    Create new java project in Eclipse

Step1: Create new java project

Step2: add UiAutomator libraries

  • Right click on project
  • Add External JARs

5. Simple script

Class TestDemo extends UiAutomatorTestCase
  public void testDemo() throws UiObjectNotFoundException {


loginWordPress(“test”, “abc1234”);


  • Add method: launchWordPress
  • And method: loginWordPress

6.    Generate build.xml file for UiAutomator project

  • Go to ANDROID_SDK/Tools/

/tools/android create uitest-project -n -t -p

  • : project name
  • : path/to/project/
  • : this is id of target platform in section 2: step 3
  • After step: build.xml will be generated in path/to/project/

7. Build UiAutomator project

  • Go to path/to/project/ and open Windows Command Line and type: ant build

Here is screenshot when build project

8.    Deploy your generated test JAR file to the test device by using the adb push command

\platform-tools\adb push /data/local/tmp/

9.    Running test

adb shell uiautomator runtest .jar -c

  • : this if name of jar file after step 3
  • : name of class that you want to execute

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.