uiautomatorviewer – To find Element IDs or xpath for Android Apps

 

So, you have got the Appium setup done & ready to write test cases in Robot Framework.

More details to get the setup up & running can be found here.

Now, you need to test an app & want to find out a way to find the Element IDs or xpath of the app.

Read On.

There are couple of ways I prefer. One is uiautomatorviewer tool & the other is appium tool.

This blog explains how to find the IDs using the uiautomatorviewer.

This tool is available both for Mac & Windows.

In this example, will try to automatically open Youtube & enter a text in the search menu of Youtube.

  1. First, install the Youtube app that you would be testing on the Android device.
  2. Connect the Android device to the development machine through USB.

On the Android device, enable Developer options & enable USB debugging.For steps to do that I would suggest you to google ‘How to enable Developer options & USB debugging in Android <version>’

There would be plenty of links which would assist you in getting this done. I won’t repeat the same steps here.

After you connect this Android device to the server through USB, a window would pop up in the mobile device asking to allow USB debugging, just make sure you click on ‘          Always allow from this computer.

3.  When you install Android SDK in the server, uiautomatorviewer is one of the tools which comes built in which helps in UI testing of the application.

Open a terminal in the server & enter.

uiautomatorviewer

ui_automator_viewer

 

4.   Open the Youtube app in the android device & now click on the top left second icon in the uiautomatorviewer tool on the development machine.

ui_automator_viewer-1

5.  Hover mouse on the search option & click on it to check the UI Element.

ui_automator_viewer-2

You can use the menu_search id to enter any text.

To use this in a Robot test case.

Check the 3rd line in the test case, the Input Text keyword takes an id=menu_search that we got from the step 5 above.

*** Settings ***

Library AppiumLibrary
Documentation demo for appium library
Force Tags demo
Resource demo/demo_resoure.txt


*** Test Cases ***
test_demo
    [Tags] 
    Open Application    http://localhost:4723/wd/hub     platformName=Android    platformVersion=5.1.1    deviceName=fd1bee6e     app=com.google.android.youtube     automationName=appium     appPackage=com.google.android.youtube      appActivity=HomeActivity
    Wait Until Page Contains    Home    timeout=10
    Input Text    id=menu_search     Appium tutorial
    Click Element     id=search_type_icon
    Close All Applications
Result of running the above test case.
Shivaram:Android shivaram$ pybot test_andriod_demo.txt 
==============================================================================
Test Andriod Demo :: demo for appium library 
==============================================================================
test_demo | PASS |
------------------------------------------------------------------------------
Test Andriod Demo :: demo for appium library | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: /Users/shivaram/projects/Android/output.xml
Log: /Users/shivaram/projects/Android/log.html
Report: /Users/shivaram/projects/Android/report.html
Shivaram:Android shivaram$ Shivaram:Android
Cheers!!

Hi there. I'm Shivaram. Security & Network Professional with around 10+ years of experience. Here on this blog to share all my testing related experience. I'm a problem solver & key to that is to come up with the right questions. Of course we then have Google for all the answers.

Leave a Reply