UIAutomatorViewer is an app testing tool, developed by Google, which comes with the Android SDK to inspect application screens from an Android device (or emulator). It offers a UI to inspect various elements on an Android screen. Simply use your mouse to navigate through the various screen components and find the selectors which you can use in your automated tests.
Using UIAutomatorView in combination with Appium is a good idea, because it allows you to find the most optimal selectors to automate any Android app.
Setting up UIAutomatorViewer
Setting up UIAutomatorViewer is easy as it comes with the Android SDK. It is located under the tools
directory as a file called uiautomatorviewer.bat
.
Once the program is started, you can click the screenshot button to indicate that you want to see a live view of the app currently running on the device. Once the live view appears, a sidepanel on the right will show a hierarchy view of the components that make up the current screen.
How do I locate elements using UIAutomatorViewer?
The right side panel of UIAutomatorViewer will contain a hierarchical view of the current application's layout structure. As you click some of the items in the panel, you will see the properties for each of these items.
Properties such as content-desc, class, resource-id and text can be helpful to construct locators which you can use in your automated Appium tests.
For example, you have a layout with a button that you want to click. You use UIAutomatorViewer to inspect the button and see that it has these properties:
content-desc: myButton
text: my-button
resource-id: com.testingbot.test:id/mybutton
class: android.widget.Button
We can now construct several locators that will each target the same element, using different selector strategies. Each of these locators can be used in an Appium test.
Using content-desc (AccessibilityId)
The content-desc
attribute can be used as an AccessibilityId
:
Using text
The text
attribute can be used as a name
:
Using resourceId
The resourceId
attribute can be used as an id
:
Using class
The class
attribute can be used as a className
: