In any test script, elements will need to be inspected in order to determine the element’s locators so that you can drive the tests and verify that the actual functionality meets expectations.
This post will cover how to inspect a native Android application’s elements using UI Automator Viewer.
The information provided is based on the understanding that Android SDK or Android Studio is already installed, in addition to having an emulator or device that has a native Android application installed. Refer to the android app automation configuration guide for further details.
Inspect elements using UI Automator Viewer
Compared to using Appium, I prefer to inspect elements using UI Automator Viewer. In my experience, UI Automator Viewer is faster and more stable for this task.
- Launch the target application on selected Emulator or Connected device
- Check your emulator/device is connected to your development machine. Via command line, access your Android SDK tools folder and execute:
>> ./adb devices
- Check that uiautomatorviewer is installed on your machine. Inside the Android SDK tools, list the files and to check that “android-sdk-macos/tools/uiautomatorviewer” is available.
- Note that it is installed via Android Studio or Android SDK. Refer to the post about the android app automation framework configuration if you need further details.
1. Launch UI Automator Viewer
- On command line, access your Android SDK tools folder & start the uiautomatorviewer:
2. Inspect elements
- Using your emulator or device, navigate to the screen with the element that you wish to inspect
- In the UI Automator Viewer interface, select the Device Screenshot button to capture a screenshot
- Interact with the screenshot by hovering and highlighting the elements you’d like to inspect
- Select an element (indicated on the screenshot by red highlight) and inspect the underlying code via the UI Automator interface
For further information, refer to the Android Developer documentation about UI Automator Viewer.
Inspect element using Appium
As mentioned, only in my own personal experience, I have found that inspecting elements in Appium is much more time consuming compared to UI Automator. However, Appium can most certainly be used to inspect elements. You can find further information about that in the Appium documentation, under Appium.app inspector section.
Converting the details from the inspector into a solid locator for your Appium automation tests
After the elements have been inspected, the locators required for Appium can be determined. The next post will cover how you can use the inspector to work out the locator required for Appium.