Thursday 4 February 2016

How to locate Android App UI elements ?

Before you commence with writing test cases in any of your choice automation tool, you need to know how will you find the UI element within you android app. It is important to understand why you need to learn this. Automation is nothing but performing actions on different UI element via test cases so before you perform these actions , it is very important that you know on which UI element you want to perform the action. So finding that unique identifier to locate the UI element within the app is becomes the first priority.

Currently I am using UI Automator Viewer for Locating android app elements which is pretty good and meets our requirement. I use chrome inspector to  locate elements for web views in hybrid apps. 

UI Automator is tool provided by android SDK which offers an interface to view and analyze UI component's properties in hierarchical manner and we can create our own xpath using these properties. (here properties are id, class name, content description, text etc)

Steps to inspect UI elements using UI Automator Viewer- 

1. Connect your device to PC with USB and turn on USB debugging as explained in HERE.
2. Go to command Line and give path till android-sdk/platform-tools/
2. run command uiautomatorviewer
3. Wait till UI Automator Viewer  window is launched.
4. click on the green icon at top left corner shown below when the app to be tested is open in your android device.

5. Mouse over the on UI element which you want to locate and then click on it to fix it.
6. Then on the right side you will find the UI properties associated with the element which you can use in your test case.

Steps to inspect Web View UI elements with Chrome-
1. Go to chrome browser
2. Type this url -chrome://inspect/devices#devices
3. click on any url listed on web page.
4. Then click on any UI element and you will get associated html source code which you can use to write your own xpath.

1 comment:

  1. Thank you for taking the time to provide us with your valuable information. we appreciate your confidence and trust in us, Thanks for sharing..Software Testing Training Institute in Chennai | Selenium Training Institute in Chennai | ALM Training Institute in Chennai