Features

UIAutomatorViewer for Automated Android Tests

  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn
  • Share on HackerNews

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:

driver.findElementByAccessibilityId("myButton");

Using text

The text attribute can be used as a name:

driver.findElement(By.name("my-button"));

Using resourceId

The resourceId attribute can be used as an id:

driver.findElement(By.id("com.testingbot.test:id/mybutton"));

Using class

The class attribute can be used as a className:

driver.findElement(By.className("android.widget.Button"));

Using UIAutomatorViewer with TestingBot

Using UIAutomatorViewer allows you to find the locators you need for your tests.
You can make sure your test automation stays functioning by choosing the right locators. The right locators are the most simple locators, which are not likely to change during the lifetime of the app.
For example, instead of choosing a resourceId, it might make more sense to assign the element a specific AccessibilityId which will not change.

TestingBot offers manual mobile app testing, which offers a Mobile Inspector. The Mobile Inspector allows you to inspect the view hierarchy of your app and find locators, similar to how UIAutomatorViewer works.

  • Share on Facebook
  • Share on Twitter
  • Share on LinkedIn
  • Share on HackerNews
TestingBot Logo

Sign up for a Free Trial

Start testing your apps with TestingBot.

No credit card required.

Other Articles

Dark Mode Testing with Appium

Perform dark mode automated testing on iOS and Android with Appium.

Read more
Angular UI Testing

Learn more about using Visual UI Testing in combination with Cypress to test Angular UI apps.

Read more
Visual Regression Testing with Python

Find out how to do automated visual UI testing with the power of Python and TestingBot.

Read more
Android Espresso Tutorial

Learn more about Android Espresso Testing in this tutorial.

Read more
Page Object Model (POM) and Page Factory with Appium

Learn more about the Page Object Model and how to use it with Appium.

Read more
Getting Started with Appium

Learn how to use Appium for automated testing. We will provide some tips and tricks, performance optimizations and ways to use Appium Inspector to troubleshoot your native mobile app testing.

Read more