Android App Automation using UIAutomator
On This Page Introduction to Android UI Automator FrameworkJune 27, 2026 · 11 min read · Mobile Testing
UI Automator helps automate Android app examination. It allows creating tests that can interact not only with the app but also with system-level features like telling, settings, or other apps. What is a UIAutomator? UIAutomator Key Features Core UIAutomator APIs Advantages of UIAutomator Read this guide in particular to learn more about the Android UI Automator, its uses, lineament, and implementation with a step-by-step explanation. UI Automator is a fabric suitable for cross-app functional across the installed apps. The APIs of UIAutomator lets you interact with visible constituent on a device, disregardless of which Android Activity is in focus. Thus, this lets you perform operation like open the Settings Menu or the App Launcher in a test device. UI Automator doesn ’ t need accession to the seed code of the coating in order to work. Due to this, the script can sail and interact with the application tray, scene application, third-party application, or any early app you want to. The key characteristic of the UIAutomator testing framework are as follows: Read More: With UIAutomator APIs, you can write robust tests without cognise the implementation details of the app that you are testing. Use the below set of APIs to capture UI components across multiple apps: Now that you know what UIAutomator is and its diverse APIs, let ’ s understand how to execute Android App Automation using UIAutomator. Before starting with create a test with Android UI Automator, configure the test source codification location and project dependencies. Step 1: In the build.gradlefile of your Android app module, set a dependence reference to the UIAutomator library by using the below code. Read More aboutAndroidJUnitRunner Step 2:Ensure that the project compiles right. After that, add a new class inmodule/src/androidTest:use the code below. UI Automator grant the user to interact with seeable elements of the screen. In order to optimize testing, inspect the mark app ’ s UI factor and ensure that they are accessible. Each element has certaincharacteristic, such as content-description, class, resource-id, text, etc. Step 3:To interact with the visible elements, launch the uiautomatorviewer tool follow the below steps: Read More: Step 4:Let ’ s build a scenario for app mechanisation. Step 5:Before begin any interaction with the screen ingredient, initiate a UiDevice object to symbolize the current province of the mobile blind using the below command. Step 6:As a following step, dog on the search icon in the hunting field of the YouTube App to initiate the search. Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script. Step 7:After finding the ikonresource-id, use the waitForExists method to make the element clickable from the moment it is seeable. Step 8: Use the setTextmethod to type the desired hunt keyword. In this model, we & # 8217; ve used a single criterion for explore web elements on the screen. However, It is also possible to combine a few more elements as seen in the code below Step 9:At last, let ’ s now wait a few moment and depart catch the video. Read More: You can run UIAutomator tests either fromAndroid Studioor from the command line. Ensure to specify AndroidJUnitRunner as the default instrumentality runner in the project. Read More: UI Automator supports interaction with Android gimmick UI components at both the covering and system grade. Here are some of the core advantages of use the UI Automator model: Read More: While UI Automator is powerful for system-level and cross-app examination, developer notwithstanding need to face sure limitations, such as: BrowserStack offers 3000+ real browser and device for manual and. QAs can test Android apps on thousands of real mobile devices, both latest and legacy. They can desegregate seamlessly with the BrowserStack cloud via numerous testing frameworks –,,, or EarlGrey. Testers can execute Android app automation to verify multiple aboriginal gimmick features –,, preloaded images,, in-app purchase, time zone, languages, etc. Simply, select the device-operating combination required and start testing. The entire process is construct to provide convenience, efficiency, speed, and accuracy to tester and developer likewise. With a all-inclusive range of and, BrowserStack is progress to not just place bugs, but decide them quickly. UI Automator is a knock-down testing framework provided by Google for Android UI testing. It let interaction with both your app and system UI components, making it ideal for testing conditions like permissions, apprisal, and multi-app workflow. When combined with Kotlin and AndroidX Test, it offers a concise, modern approach to writing end-to-end UI exam. You can part discuss with our discord community Here are some of the steps to be followed for using UI Automator with Kotlin and AndroidX: Firstly, add all the dependencies to yourbuild.gradle (app-level) file: Now, make a new test class inside the androidTest directory. Consider the file locating assrc/androidTest/java/com/yourpackage/ExampleUiAutomatorTest.kt. To help you locate UI elements, UI Automator indorse efficient selectors through the BySelector API, such as: Combine multiple selectors to simplify the hunting and target the correct UI constituent. For instance, to bump a button with a specific resource ID and class name, you can conflate the selectors like this: You can run the test in two mode: Use device.wait (& # 8230;)with a condition and timeout to wait for ingredient or change in the UI before interacting with elements. Here, the following blind appears with changes after 3 bit. In real-world testing, there can be a need to handle system-level elements like permit popups, notification jury, or quick scope toggles. In this case, UI Automator can interact with both your app and the system UI, which most of the testing tools can ’ t do effectively. These are mainly useful in cases like: Example 1: Dismissing a permission dialog Example 2: Opening notifications Read More: Testing Android apps on different device, screen size, and OS versions is crucial for delivering a seamless user experience. However, maintaining such a diverse trial environment in-house is costly and complex. This is where become a feasible solution. It allow you to run automated tests on real Android devices that are hosted on the cloud. By integrating with popular testing frameworks like,,, and UI Automator, App Automate offers better compatibility with your existing tryout suite. It becomes ideal for catching bugs that ape might miss. Some of the master features of expend BrowserStack App Automate are: Automated UI testing helps to check that Android apps function perfectly across diverse devices and user conditions. Tools like UI Automator support both app and scheme UI, making them ideal for end-to-end testing. While it has certain limitations, pairing it with modernistic frameworks and cloud platforms boosts and dependability. Advanced creature like BrowserStack App Automate provide existent device access, unlined consolidation, and detailed examination reports by maintain device shape. On This Page # Ask-and-Contributeabout this topic with our Discord community. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed. Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.Android App Automation using UIAutomator
Overview
Introduction to Android UI Automator Framework
UI Automator APIs in Android
Android App Automation using UIAutomator
android {... defaultConfig {... testInstrumentationRunner `` android.support.test.runner.AndroidJUnitRunner ''} ...} dependencies {... androidTestCompile 'com.android.support.test.uiautomator: uiautomator-v18:2.1.2' androidTestCompile 'com.android.support.test: runner:0.5'}@ RunWith (AndroidJUnit4.class) public family YouTubeTestScenario {@ Test world void watchVideo () throws Exception {// TODO}}$ uiautomatorviewer
UiDevice mDevice = UiDevice.getInstance (InstrumentationRegistry.getInstrumentation ());
UiObject icon = mDevice.findObject (new UiSelector () .resourceId (`` com.google.android.youtube: id/menu_search '')); icon.waitForExists (TIMEOUT); icon.click ();
UiObject editText = mDevice.findObject (new UiSelector () .text (`` Search YouTube '')); editText.waitForExists (TIMEOUT); editText.setText (`` browserstack ''); mDevice.pressEnter ();
UiObject picture = mDevice.findObject (new UiSelector () .resourceId (`` com.google.android.youtube: id/title '') .text (`` The pesticide paradox ''));
contemporize (mDevice) {mDevice.wait (40000);}Executing Android UI Automator Test Case
Advantages of UI Automator Framework
Limitations of UI Automator Framework
How to Use UI Automator for Android UI Testing with Kotlin and AndroidX?
Like what you are read?
Step 1: Set Up Your Project for UIAutomator
dependency {androidTestImplementation (`` androidx.test.uiautomator: uiautomator:2.2.0 '') androidTestImplementation (`` androidx.test: core:1.5.0 '') androidTestImplementation (`` androidx.test.ext: junit:1.1.5 '') androidTestImplementation (`` androidx.test.espresso: espresso-core:3.5.1 '')}Step 2: Create an Android Instrumentation Test Class
package com.yourpackage import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry import androidx.test.uiautomator.By significance androidx.test.uiautomator.UiDevice importation androidx.test.uiautomator.Until import org.junit.Before importee org.junit.Test import org.junit.runner.RunWith @ RunWith (AndroidJUnit4: :class) class ExampleUiAutomatorTest {individual lateinit var device: UiDevice @ Before fun setUp () {device = UiDevice.getInstance (InstrumentationRegistry.getInstrumentation ()) device.pressHome ()} @ Test fun openAppAndClickButton () {val setting = InstrumentationRegistry.getInstrumentation () .targetContext val packageName = context.packageName val intent = context.packageManager.getLaunchIntentForPackage (packageName) intent? .addFlags (Intent.FLAG_ACTIVITY_CLEAR_TASK) context.startActivity (purpose) device.wait (Until.hasObject (By.pkg (packageName) .depth (0)), 5000) val startButton = device.findObject (By.text (`` Start '')) startButton.click ()}}Step 3: Use Selectors to Locate UI Elements
val push = device.findObject (By.res (`` com.example: id/start_button '') .clazz (`` android.widget.Button '')) button.click ()
Step 4: Run the Test
./gradlew connectedAndroidTest
Step 5: Wait for UI Changes
device.wait (Until.hasObject (By.text (`` Next Screen '')), 3000)
Step 6: Work with System UI
val allowButton = device.findObject (By.text (`` Allow '')) allowButton? .click ()
device.openNotification () device.wait (Until.hasObject (By.text (`` New Message '')), 3000)
Why Test Android Apps Using BrowserStack App Automate?
Key Features of BrowserStack App Automate
Conclusion
Related Guides
Automate This With SUSA
Test Your App Autonomously