The Android Test Recorder is a tool for automating UI tests, similar to Google's Espresso Test Recorder. It simplifies the process of creating test scripts for Android applications.
- Runs in the Android OS, don't need adb connection
- Compatible with Android 8 to 14.
- Supports apps built with Flutter and Compose, which doesn't have a Android view hierarchy.
- No rooting required.
- Capture User Interactions: Utilizes AccessibilityService, MediaProjection, and OverlayView to capture user clicks.
- Automatic Script Generation: Automatically generates test scripts based on captured user interactions.
- Helper Code for Test Classes: Incorporates helper code in your base test class.
import androidx.test.uiautomator.By
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.Until
import androidx.test.platform.app.InstrumentationRegistry
open class BaseTest {
private val uiDevice: UiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
fun clickText(text: String) {
val selector = By.text(text)
val obj = uiDevice.findObject(selector)
obj?.let {
if (!it.wait(Until.clickable(true), 5000)) {
throw AssertionError("View with text '$text' not found or not clickable")
}
it.click()
} ?: throw AssertionError("View with text '$text' not found")
}
fun clickContentDescription(description: String) {
val selector = By.desc(description)
val obj = uiDevice.findObject(selector)
obj?.let {
if (!it.wait(Until.clickable(true), 5000)) {
throw AssertionError("View with content description '$description' not found or not clickable")
}
it.click()
} ?: throw AssertionError("View with content description '$description' not found")
}
}
- apps: Contains the main application of the recorder.
- model: Includes ViewModels and model-level code for the main application.
- common: Features quality of life code that enhances the overall functionality.
- dummy-app-for-testing: A simple application built using Jetpack Compose, serving as a test subject for the main app.