Tuesday, December 3, 2013

What is "Ui Automator Viewer"?

uiautomatorviewer is 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 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.



 


To analyze the UI components of the application that you want to test:
  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:
    $ uiautomatorviewer
  4. To capture a screen for analysis, click the Device Screenshot button in the GUI of the uiautomatorviewer tool.
    Note: If you have more than one device connected, specify the device for screen capture by setting theANDROID_SERIAL environment variable:
    1. Find the serial numbers for your connected devices by running this command:
      $ adb devices
    2. Set the ANDROID_SERIAL environment variable to select the device to test:
      • In Windows:
        set ANDROID_SERIAL=<device serial number>
      • In UNIX:
        export ANDROID_SERIAL=<device serial number>

    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 the uiautomatorviewer tool. 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 the Toggle NAF Nodes button to see UI components that are not accessible to the uiautomatortesting 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

Index 4                              
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