
What is UIAutomatorViewer?
UIAutomatorViewer Tutorial: UIAutomatorViewer is a GUI-based inspection tool provided by the Android SDK that helps testers analyze the UI components of an Android application. It is used to capture the structure, properties, and hierarchy of UI elements in an app under test.
This tool is crucial for automation testers using Appium as it allows them to identify elements using properties like resource-id, text, class, and content-desc.
Why Use UIAutomatorViewer for Appium Automation?
UIAutomatorViewer Tutorial: To write automation scripts in Appium, you need to uniquely identify UI elements within your Android app. UIAutomatorViewer makes this easy by:
- Displaying the UI element tree
- Highlighting properties of individual UI nodes
- Assisting in generating XPath and locators
- Visualizing screen layouts for better test strategy
How to Download & Install UIAutomatorViewer
UIAutomatorViewer Tutorial: UIAutomatorViewer is part of the Android SDK. Follow these steps to install:
Step-by-Step Installation Guide:
Once installed, navigate to:
php
<SDK Directory>\tools\bin
- Locate and double-click the file named uiautomatorviewer.bat (for Windows) to launch the UIAutomatorViewer tool.
How to Use UIAutomatorViewer to Inspect Android Elements
Step 1: Enable Developer Options
- Go to your Android device settings → About Phone → Tap “Build Number” 7 times to enable Developer Options.
- Then go to Developer Options and enable USB Debugging.
Step 2: Connect Android Device to PC
- Use a USB cable to connect your Android phone to the system.
Step 3: Open Your Test Application
- Launch the application you want to test (e.g., Guru99 app) on your mobile device.
Step 4: Take a Screenshot with UIAutomatorViewer
- Open UIAutomatorViewer.
- Click the “Device Screenshot” button.
- A snapshot of your current screen will appear, along with the UI hierarchy.
Understanding UIAutomatorViewer Interface
UIAutomatorViewer Tutorial: In the UIAutomatorViewer window, you’ll find two major sections:
- Upper Panel (Node Tree): Displays the hierarchy of UI components.
- Lower Panel (Properties): Shows the selected element’s properties like:
- text
- resource-id
- class
- content-desc
- text
Example: If you click on a “Quiz” button, the properties of that button will be shown, which you can use in Appium scripts.
How to Use Element Properties in Appium Scripts
UIAutomatorViewer Tutorial: Here’s how different properties can be mapped in Appium:
UIAutomatorViewer Property | Appium Locator |
text | name or text |
resource-id | id |
class | className |
content-desc | AccessibilityId |
You can also create XPath expressions using these attributes for more complex selectors.
Example:
java
driver.findElementByXPath(“//android.widget.Button[@text=’Quiz’]”).click();
Common UIAutomatorViewer Error and Fix
Error:
pgsql
No Android devices were detected by adb
Solution:
- Ensure your Android device is connected properly.
- Confirm USB Debugging is enabled.
Run the following in Command Prompt to verify:
nginx
adb devices
If your device is listed, UIAutomatorViewer should recognize it.
official Android developer site.