Everything about Android UI Automator to Test Mobile Application

Android UI Automator

Automation is crucial for Software Testing once it make feasible to create test steps as many times as required, across the diverse software versions. This process can be tedious to perform manually and very error prone as it is done by human. Manual process forget to perform necessary steps or misunderstand some test step, causing invalid results. This blog is all about how UI Automator script simply test any Android application. This testing has completely transformed the working of Android Programmer regarding the mobile app development work in a smooth & streamlined manner.

Introduction to UIAutomatorViewer

UIAutomatorViewer comes integrated with Android SDK manager and it is a UI inspector GUI tool that helps us to inspect UI elements of an Android mobile app. Inspecting of an application is essential as we require locators like resource IDs, class, text of an Android application component to automate the application.

A screenshot of the current screen is captured by the UIAutomatorViewer. By clicking on any element, information about the class can be accessed that is used to represent, the element on the screen along with all the properties mentioned on the right-hand side of the tool.

You can install this UIAutomatorViewer tool in two ways.

1. Android Studio

If you are aware of the Android application testing/development, then simply install Android Studio. It includes all the Build, platform, and SDK tools. Thus by installing the Android Studio, all the tools are accessed with it. It is recommended to go with Android Studio when a good laptop/PC is available. Because it consumes considerable RAM on your device and needs high-speed internet connection to download and install all the requirements. If come across any trouble simply hire Android App Developer from a reputed development agency experience in app development.

2. Command-line Tools Only

Apart from downloading Android SDK manager another method is pretty much straight forward too.

  • Open tools and click the platform-tools link to download the files.
  • Create a folder and extract the downloaded tools and platform-tools here.
  • Within the tools, you will get an android.bat folder, click or run the bat file and the Android SDK Manager window will be displayed. Open the platform version, and click install. You need to select platforms and build tools for the needed version of the Android API.
  • Accept the terms and conditions. Download and install platforms & build tools. Make sure that all the needed files are present under the AndroidSDK folder.
  • How to Perform Black Box Testing?

    1. Using UI Automator for Cross Component Testing

    Functional or black-box UI testing test the complete application and not only the single component of an application. The Android SDK includes the uiautomator Java library to create user interface tests and has an engine to run these user interface tests. Both tools need Android OS on the device that is used to test. Androids uiautomator offers the UiDevice class to communicate with the device, the UiSelector class to identify elements on the screen and the UiObject which recommends user interface elements and is designed based on the UiSelector class. The UiCollection class select a number of user interface elements at the same time and UiScrollable permits scrolling in a view to find an element.

    2. Accessing the View Information with uiautomatorviewer

    Android offers the uiautomatorviewer tool, which allows Mobile App Development Company to analyze the user interface of an application. This tool can be used to find the index, text or attribute of the mobile application. This tool facilitates naïve programmers to analyze an application and create tests for it via the uiautomator library. To launch the uiautomatorviewer tool, switch on the command line to the android-sdk/tools/ directory and start the tool via uiautomatorviewer.

    Wrapping Up

    This is how we a UI Automator test script is created with no access to the application source code. I hope this blog have helped you understand the whole concept properly using your own test scripts, improving test coverage and eliminating manual effort.

    Frequently Asked Questions

    1. What is Android UI Automator?

    UI Automator is a UI testing framework suitable for cross-app functional UI testing across system and installed apps. This framework needs Android 4.3 or higher. The UI Automator APIs allows you to perform operations such as opening the Settings menu or the app launcher in a test device.

    2. How do I use UIAutomator on Android?

    From the Project Explorer, right-click on the new project that you created, then select Properties > Java Build Path, and do the following −Click Add Library > JUnit then select JUnit3 to add JUnit support.
    Click Add External JARs and navigate to the SDK directory.

    3. Why is automation needed?
    Automation brings in necessary agility to testing and helps it to respond faster and more effectively to changes. Agility requires frequent code deployments, which can also be automated. This frees testers from mundane, repetitive tasks so that they can focus more on testing.

    4. Why do we need automated testing?

    Benefits of Automation Testing:

  • 70% faster than the manual testing.

  • Wider test coverage of application features.

  • Reliable in results.

  • Ensure Consistency.

  • Saves Time and Cost.

  • Improves accuracy.

  • Human Intervention is not required while execution.

  • Increases Efficiency.

  • 5. How do I start Automator UI?

    To launch the uiautomatorviewer tool:

  • Launch the target app on a physical device.

  • Connect the device to your development machine.

  • Open a terminal window and navigate to the /tools/ directory.

  • Run the tool with this command: $ uiautomatorviewer.