Ui Automator Viewer

uiautomatorvieweris a GUI tool to scan and analyze the UI components of an Android application. Using this tool, you can take a snapshot of the foreground UI screen on any Android device that is connected to your development machine.

The UI automation navigator allows elements to be categorized into specific views. From most general to most specific, these views are: Raw view – The full tree of automation elements which closely follows the native programmatic structure of an application. This is the most detailed view available. Control view – This is a subset of the. Jun 14, 2021 'UIautomatorviewer' is a GUI tool to scan and analyze the UI components of an Android application.To automate any android application using Appium, a user needs to identify the objects in AUT (Application under test).



The uiautomatorviewer tool provides a convenient visual interface to inspect the layout hierarchy and view the properties of the individual UI components that are displayed on the test device. Using this information, you can later create uiautomator tests with selector objects that target specific UI components to test.

Download

Not


To analyze the UI components of the application that you want to test:
Viewer
  1. Connect your Android device to your development machine.
  2. Open a terminal window and navigate to<android-sdk>/tools/.
  3. Run the tool with this command:
  4. To capture a screen for analysis, click theDevice Screenshotbutton in the GUI of theuiautomatorviewertool.
    Note:If you have more than one device connected, specify the device for screen capture by setting theANDROID_SERIALenvironment variable:
    1. Find the serial numbers for your connected devices by running this command:
    2. Set theANDROID_SERIALenvironment variable to select the device to test:
      • In Windows:
      • In UNIX:

    If you are connected to only a single device, you do not need to set the ANDROID_SERIAL environment variable.

  5. View the UI properties for your application:
    • Hover over the snapshot in the left-hand panel to see the UI components identified by theuiautomatorviewertool. You can view the component’s properties listed in the lower right-hand panel, and the layout hierarchy in the upper right-hand panel.
    • Optionally, click on theToggle NAF Nodesbutton to see UI components that are not accessible to theuiautomatortesting framework. Only limited information may be available for these components.



To analyze the UI components of the application that you want to test: In the above screenshot attached, when we hover the App Tray icon at the center of the screen, tool displayed the following properties

Index4
classandroid.widget.TextView
packagecom.android.launcher
content-descApps
checkablefalse
checkedfalse
clickabletrue
enabledtrue
focusabletrue
focusedtrue
scrollabletrue
long-clickablefalse
passwordfalse
selectedfalse
bounds[901,973][1018,1104]

The description itself is self explanatory,

Index: component index. if there are multiple components of the same type exists, then index varies.

class: class name
package: package name
content-desc: description of the component that was given at the time of development
checkable: can it be checked? This option is applicable for checkboxes
checked: is it checked? if the checkbox is selected, it's value becomes true
enabled: if the component is disabled, it's value is false
focusable: if the component cannot be focused on hover, then the value is false
long-clicable: if the component supports long click, then the value becomes true
password: if it is password field?, then true
selected: if the component is selected, then value becomes true
bounds: coordinates

What is UiAutomatorViewer?

'UIautomatorviewer' is a GUI tool to scan and analyze the UI components of an Android application.To automate any android application using Appium, a user needs to identify the objects in AUT (Application under test). With 'UIautomatorviewer' you can inspect the UI of an android application to find out the hierarchy and view different properties (id, text…) of the element.

While executing automation scripts, Appium uses 'Uiautomatorviewer' to identify different properties of the object and use the properties to identify the required object.

In this tutorial, you will learn-

Ui Automator Viewer Mac

How to Download & Install UIAutomator

'Uiautomatorviewer' is a part of the Android SDK manager and will be accessible once you install the SDK manager. Download and install Android SDK manager from here

Once Android SDK installed, navigate to link You'll notice a batch file with name . Double click on it to launch 'Uiautomatorviewer' GUI

How to use Uiautomatorviewer to find objects in my application

  1. Enable 'developer' options on your device. Click here to know how to enable developer options on Android devices
  2. Connect your android device to PC via USB cable
  3. Select 'Guru99' app from applications
  1. Click the 'Device screenshot' button to refresh the 'Uiautomatorviewer' and to load the guru99 application GUI on 'Uiautomatorviewer'
  1. After refresh is completed, a screenshot of Guru99 application opens
  1. As you see in the above image, on the right side of the window there are 2 panels.

Ui Automator Viewer In Android

Upper panel contains node hierarchy the way the UI components are arranged and contained, clicking on each node gives properties of UI elements in the lower panel

  1. Select 'Quiz' button in the above image to view different properties (text, resource-id...)

How to use these properties to identify elements for automation

Well, you cannot use the properties directly, each property has other names. Let's see how to use those properties values to work. Following attributes can be used to identify 'Quiz' button in Guru99 app.

  • text attribute can be used as 'name'
  • resource-id attribute can be used as 'id'
  • class attribute can be used as 'className'
  • content-desc attribute can be used as 'AccessibilityId'

    Along with above attributes, we can write xpaths for object identification

Error one might encounter while using Uiautomatorviewer

  • I see the error- 'No Android devices were detected by adb' as shown in below screenshot how I can resolve this

Ui Automator Viewer Download

Solution: Make sure your device is connected to PC