Friday, January 22, 2016

Uiautomatorviewer Tutorial

Identifying Android application (AUT) objects using Uiautomatorviewer to write automation scripts
To automate any android application using Appium, user needs to identify the objects in AUT (Application under test).
While executing automation scripts, Appium uses "Uiautomatorviewer" to identify different properties of the object and use the properties to identify the required object.

What is it?

"UIautomatorviewer" is a GUI tool to scan and analyze the UI components of an android application. With "UIautomatorviewer", you can inspect the UI of an android application in order to find out the hierarchy and view different properties (id, text…) of the element.

Where to get it?

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

How to get started?

Once Android SDK installed, navigate to link c:\users\\AppData\Local\Android\sdk\tools you'll notice a batch file with name 'uiautomatorviewer.bat'. 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.
  • Upper panel contains node hierarchy the way the UI components are arranged and contained, clicking on the each node gives properties of UI element 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'm seeing the error- "No Android devices were detected by adb" as shown in below screen shot how I can resolve this
Solution: Make sure your device is connected to PC

No comments:

Post a Comment

Evil Twin attack

Evil Twin Attack is attack is frequently carried upon wireless access points with malicious intentions. This attack happens when...