UiAutomator is a tool provided by Google which allows us to write automated tests to perform black box testing. In other words we can use UiAutomator to test the behavior of an application or device.
In this tutorial I will go through how to set up UiAutomator, so lets get started.
You will first need to download the Android SDK, I would recommend downloading Android Studio which comes bundled with the SDK. You can download this from the Android website. After the download is complete install the IDE and save the SDK in an appropriate location. I have saved my SDK in the default location (C:\Users\Hadi\AppData\Local\Android\sdk).
Open the SDK Manager and install the appropriate Android API. I have installed API 22 (Lollipop) and API 19 (Kitkat). You MUST also download the Android Support Repository and Android Support Library which is located in the Extras folder.
After everything had been installed, close the SDK Manager and open the folder you have saved your SDK in then navigate to platforms > android-22. Copy the android.jar and uiautomator.jar files.
Open up Android studio and select to start a new Android Studio project. While setting up the project you will be asked if you want to Add an activity to Mobile, you can select “Add no Activity”.
Once the project has been built, change to the Project view in order to see the full project structure, expand app and inside there you will see the libs folder. Paste the android.jar and uiautomator.jar files you had previously copied into the libs folder.
Next we will need to add these libs to the project as a dependency. We can do this by right clicking on the project and selecting Open Module Settings Alternatively you can press F4). Select the app module and click on the Dependencies tab, then add file dependency. Add the 2 jar files.
Once the dependencies have been added you can start using the UiAutomator framework.
In the next tutorial I will be creating a simple UiAutomator test and running the test on a device.