Next-Gen App & Browser Testing Cloud
Trusted by 2 Mn+ QAs & Devs to accelerate their release cycles

Learn how to automate Android apps using UI Automator to perform functional UI testing across the device and installed apps.

Yogendra Porwal
January 11, 2026
UI Automator is an Android testing framework that allows you to automate UI testing of Android apps. It enables interaction with UI elements, sending input events, and verifying mobile app behaviors on emulators or real devices.
UI Automator is a framework to automate UI testing of Android apps. With UI Automator, you can perform interactions with UI elements and test app behaviors on emulators or real devices.
How to Run UI Automator Test
Here are the high-level steps to run Android UI Automator tests:
UI Automator is a framework for automating user interactions on mobile apps and system UI components on Android devices, such as launching the settings menu or interacting with the app launcher.
You can also locate UI components using intuitive attributes like visible text or content descriptions, without relying on internal implementation details of the mobile app.
UI Automator is based on instrumentation APIs and works with the AndroidJUnitRunner test runner. So, it is suitable for black-box testing scenarios where tests simulate user behavior without accessing the app’s codebase.
Before writing your first Android UI Automator test for Android app testing, ensure you meet the following prerequisites:
Note: Test your mobile apps on real Android devices. Try TestMu AI Today!
Here we’ll use an Android emulator to execute tests. Once you have set up the Android emulator, let’s add the UI Automator dependencies:
dependencies {
...
androidTestImplementation ‘androidx.test.ext:junit:1.2.1’
androidTestImplementation ‘androidx.test:runner:1.2.0’
androidTestImplementation ‘androidx.test.uiautomator:uiautomator:2.3.0’
}

Let’s write a test to open the proverbial app and verify the button functionality.
Test Scenario:
Once your Android emulator is up, run the adb install <path-to-TestMu AI-proverbial-apk-file> command to install the TestMu AI proverbial app.
Implementation:
For this use case, we will initialize the UiDevice instance and press the Home button to ensure the test starts from the home screen.
@Before
public void setup() {
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
device.pressHome();
}
This setup will also include the launch of the proverbial app with the ADB command.
//start Proverbial app with adb command
device.executeShellCommand("am start -n com.lambdatest.proverbial/.MainActivity”);
// Validate that activity has been opened.
Assert.assertTrue(device.hasObject(By.pkg(“com.lambdatest.proverbial”)));
// initialize the text label element
UiObject2 textElement = device.findObject(By.res(“<replace_with_package_name_of_app>”, "Textbox"));
// Assert the initial text
Assert.assertEquals("Hello! Welcome to lambdatest Sample App called Proverbial", textElement.getText());
UiObject2 textButton = device.findObject(By.res(PACKAGE_NAME, "Text"));
//Click on Text button to update the element
textButton.click();
//Assert that text has been updated.
Assert.assertEquals("Proverbial", textElement.getText());
From the Android Studio, click Run ‘ProverbialTest’ to execute the tests:
You can notice that your test is executed and passed.

If you want to run Android automated tests at scale, you can leverage a cloud-based testing platform like TestMu AI. It is a GenAI-native test execution platform that offers a scalable real device cloud to run automated tests on real Android devices without the need for physical infrastructure.
With TestMu AI, you can test across a wide range of Android and iOS devices, covering multiple OS versions and device brands like iPhone, Samsung, Google Pixel, etc. It also supports automation using popular frameworks like Appium, Espresso, and XCUITest, enabling faster, more reliable mobile app testing at scale.
Let’s understand the key APIs of UI Automator that help interact with Android apps and their UI components, allowing automation of clicks, text input, scrolling, and more.

To write Android UI Automator tests that are both stable and maintainable, you can consider the following best practices:
If a test modifies settings or login state, make sure to clean that up afterward using @After methods. This keeps tests independent and repeatable.
Avoid relying on visible text, as it can change or get localized, making your tests flaky. If you’re building the app, add android:contentDescription to key elements to make them both testable and accessible.
Also, use @SdkSuppress to skip tests that aren’t applicable on certain Android versions.
If you’ve made it this far, you now have a solid foundation for using UI Automator to automate Android app testing, from setup and writing tests to understanding key APIs.
UI Automator is great for functional UI testing. However, running Android tests across many devices and OS versions can be complex and time-consuming. That’s where a platform like TestMu AI becomes helpful. It lets you instantly run automated tests on real Android devices in the cloud, no physical labs or maintenance needed.
Did you find this page helpful?
More Related Hubs
TestMu AI forEnterprise
Get access to solutions built on Enterprise
grade security, privacy, & compliance