UIAutomator, XCUITest & Locators

Get introduced to UIAutomator, XCUITest, and understand the various locator strategies.

UIAutomator

UI Automator is a UI testing framework suited for the functional black-box tests of system apps and user-installed apps without knowing how the app is implemented. It provides APIs that allow the user to interact with the applications. UIAutomator and uiautomatorviewer come bundled with Android SDK.

The minimum requirement of UIAutomator is Android 4.3 (API level 18) or higher.

UIAutomator has the following capabilities:

  • It bundles a uiautomatorviewer that allows us to view and inspect the layout hierarchy of the application.
  • APIs to retrieve the state of the application.
  • APIs to interact with the application by performing operations like – click, sending keys, etc.

To access uiautomatorviewer, run the following command:

$ANDROID_HOME/tools/bin/uiautomatorviewer

The below images show:

(1) the state of the uiautomatorviewer when no android phone(s) are connected. When clicking on the highlighted portion in the screenshot, the layout of the current visible screen loads as shown in the second image.

(2) the state of the uiautomatorviewer. As we move the cursor and hover over the contents of the left side of the app screen displayed on the left side, the corresponding element gets highlighted on the layout displayed on the right. It also shows the properties of that highlighted element below the layout.

Get hands-on with 1400+ tech skills courses.