Object Identification in Mobile Automation Using UIAutomator VIEWER

14 / Jan / 2016 by Kimi Agarwal 6 comments

Mobile testing is a very hot topic nowadays. There are two ways to test how the application is interacting with the user on the mobile device one is manually and the other is through automation.

Manual testing takes lot of time and it’s a very slow process. While automation testing is more efficient and effective process. In automation testing we have to write the test cases to cover the specific scenarios and then run those test cases automatically. While we are writing the test cases, we have to identify the objects, and for this we use UIAutomator VIEWER.

Appium uses UIAutomator VIEWER.

Appium is an open source mobile automation tool which is useful to automate android and IOS platform apps. It support Native, Hybrid and Web Application.

How to use UIAutomator VIEWER

UIAutomator Viewer is a GUI tool that comes with Android SDK. It is used to examine and inspect the UI components of an Android Application that are visible on the forefront of the device.

STEPS:-

  1. Install the android SDK. When the SDK has been installed in the system, you have to move that SDK folder from C Drive to another Drive suppose E Drive.
  2. Under SDK folder, go to SDK then go to the Tool Folder. Double click on UIAutomator viewer batch file to launch it

You will find uiautomatorviewer.bat file in Tools folder of SDK. e.g. E:\SDK\tools.

  1. Attach your device with your PC using USB cable.
  2. Verify the device is connected to the system by using adb devices command on CMD prompt.

cmd_Image

  1. Enable the developer option in the Android Device from the Settings.
  2. Select LinkedIn application.
  3. Click on the device screenshot button and the LinkedIn application opens up.

UIAutomatorViewer_Image

     How to identify elements for automation

  • text attribute can be used as “name” findElement(By.name(“Sign in”));
  • resource-id attribute can be used as “id” findElement(By.id(“com.linkedin.android:id/login_button”));
  • class attribute can be used as “className” findElement(By.className(“android.widget.Button”));

 

Challenges with the tool and there resolution

  1. To use UIAutomator VIEWER please make sure Android SDK is installed in the laptop.
  1. UIAutomator VIEWER does not support WebView. Firebug is used to identify the objects.
  1. Works on Android Devices with Version 4.1 (or higher).If you want to test UI on lower versions of Android Devices with Version2, use ‘Espresso’.
  1. When the mobile device is not connected to the PC and the user click on the ‘Device Screenshot’ button on top right corner of the screen, an error will occur “No Android devices were detected by adb”.

 

Comparison between UIAutomator Viewer and Calabash

  1. UIAutomator Viewer only works on API level 16 and above which means you can’t run your test on older devices while Calabash works on API level 8 and above.
  1. Unlike Calabash, UIAutomator Viewer runs on your computer which is driven by a server on the device that interacts with the app.
FOUND THIS USEFUL? SHARE IT

comments (6)

  1. Ritesh

    I am new to appium..I am able to launch the app successfully through below code –
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);
    capabilities.setCapability(“deviceName”, “My Device”);
    capabilities.setCapability(“platformVersion”, “6.0”);
    capabilities.setCapability(“platformName”, “Android”);
    // capabilities.setCapability(“app”, app.getAbsolutePath());
    capabilities.setCapability(“app”, “C:\\RITESH\\SELENIUM\\APPIUM\\Appium Setup\\Setup\\SGMA PREPROD_Build_026.apk”);
    capabilities.setCapability(“appPackage”, “com.sgma.preprod”);
    capabilities.setCapability(“appActivity”, “com.sgma.preprod.SGMAPREPROD”);
    // For url check your Appium setting
    driver = new AndroidDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);
    WebDriverWait wait=new WebDriverWait(driver, 20);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    // Clear the user id
    //driver.findElement(By.xpath(“//android.widget.EditText[@index=’0′]”)).clear();
    driver.findElement(By.xpath(“//android.widget.EditText[@index=’0′]”)).sendKeys(“8378034”);
    //Enter Password
    driver.findElementByName(“Enter password”).click();

    If I run the same program again and again it first re-install and then again install the app on my mobile device.
    On my second run – I dont want my code to un- install the app. How I can handle this scenario? Just wanted to launch the app without installing.
    Please help!

    Reply
  2. Vishal G

    Nice Blog Kimi.
    I am looking to identify the id or Name of an object /element of an iOS app using Appium inspector or any other available method.
    I can currently use the xpath given by appium inspector but not IDs/Name.
    your help will be highly appreciated.

    Regards
    Vishal

    Reply
    1. Vishal G

      Hi Kimi,

      Can you please respond to my above query. I am waiting for your help on this.

      Regards
      Vishal

      Reply
      1. Kimi Agarwal

        Locators are same for all Android and iOS
        you can use
        By.Name, By.css, By.xpath when id is not provided for any object in the app.

        Reply
        1. Vishal G

          Thanks for your reply on this but I don’t think Locators are same for Android and iOS. they are different in android and iOS. i am able to find elements by Name and class in Android but not in iOS. Can you please confirm the same.

          Regards
          Vishal

          Reply
          1. Kushal Puri

            I would suggest to check the id and name from developer if you unable to find them. Usually it’s a good practice to keep the id nd name same on both platforms

Leave a Reply to Vishal G Cancel reply

Your email address will not be published. Required fields are marked *