Header Ads

  • Breaking News

    How to identify Objects with UIAutomator Viewer for Mobile automation?

    For mobile application testing automation is must for regression. UIAutomator is very powerful tool to capture Android application objects for automation with Appium. (will write detailed articles on Appium). You can see Resource IDs, Text, Class hierarchy, Content-desc, checked, clickable etc and can identify elements by it. In this article we will discuss what is UIAutomator, how to set up UIAutomator, How to Identify elements using UIAutomator?

    what is UIAutomator?

    UIAutomator is a GUI Tool. It helps android app automation testers to scan and analyse android application element. You can take screenshot of screen by UIAutomator and Identify elements displayed on screen by resource Ids, Text etc. This is how it looks like –


    How to set up UIAutomator?

    • First of all, you need to install Android SDK
    • In SDK > Tools you can find UIAutomatorViewer (If you are downloading latest SDK then it will be under SDK>Tools>Bin).
    • Now need to set system environment variables for android SDK.
    • Set Variable Name ANDROID_HOME with Path of SDK, In Path add path of ANDROID_HOME/Platform-tools
    • ANDROID_HOME/Build-tools
    • Now make sure your android device is connecting with ADB command (try adb devices command in command prompt). 
    • If you have problem with setting up ADB read this post How to setup ADB in windows ?
    • Now you all set to open UIAutomatorViewer.

    How to Identify elements using UIAutomator?

    How to Identify elements using UIAutomator?

    Here is the screenshot of my twitter profile in UIAutomator. Now let’s say you want the identifiers of Edit button.
    Here on right side you can see hierarchy of classes. Bellow that you can see Node detail. In that there are 5 fields text, resource-id, class, package, content-desc. These are the fields you can use to identify your element. From those we need to find unique one (that should not be same for other objects of screen). Here you can see text and resource-id are unique fields, they clearly mentioned “edit profile”. Class and package name could be similar for others objects as well. Here are the some Appium driver methods to identify the elements.
    • PublicfindElement(java.lang.String by,java.lang.String using)
    • Parameters
    • by - is a string selector
    • using - is a value of the given selector
    • public findElementById(java.lang.String id)
    • public findElementByLinkText(java.lang.String using)
    • public findElementByName(java.lang.String using)
    • public findElementByClassName(java.lang.String using)
    • public findElementByXPath(java.lang.String using)
    we will discuss these method in detail in future posts on Appium.

    After identifying object on screen, you can get the values of clickable, enable, checked, focused etc. You can use webelement.getText(String) to get the values of that attribute in string format. There are other methods like getTagName(String) also.

    Feel free to comment if you didn’t get something. We will add more posts on Appium, Appium methods, Selenium and other automation tips in this blog. Please follow this site by submitting your email Id or follow on facebook, twitter and google plus.

    Post Top Ad

    Post Bottom Ad