Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automation testing framework for Jetpack compose

we have re-written couple of features in Jetpack Compose successfully. we have hit a roadblock where our QA says the existing automation script they have written does not work anymore for compose UI screens.

Background abt the automation script: QA uses Appium script which uses UIAutomator2 to automate the elements. For identifying locator(ID) - appium inspector is used. We don't have ID's in compose UI. We tried adding testTag and not seeing it in appium inspector.

Pls share what kind of framework changes you have to do for Automation script to support compose UI.

Thanks

like image 977
Sathis Kumar Avatar asked Oct 14 '25 16:10

Sathis Kumar


2 Answers

UPDATE

According to compose official docs and Interoperability with UiAutomator (since Compose version 1.3.3):

The testTagAsResourceId can be enabled for the particular composables subtree in your composables hierarchy to ensure all of nested composables with Modifier.testTag are accessible from UiAutomator.

In Compose:

Scaffold(
    // Enables for all composables in the hierarchy.
    modifier = Modifier.semantics {
        testTagsAsResourceId = true
    }
){
    // Modifier.testTag is accessible from UiAutomator for composables nested here.
    LazyColumn(
        modifier = Modifier.testTag("myLazyColumn")
    ){
        // content
    }
}

In Tests:

val device = UiDevice.getInstance(getInstrumentation())

val lazyColumn: UiObject2 = device.findObject(By.res("myLazyColumn"))
// some interaction with the lazyColumn
like image 67
superus8r Avatar answered Oct 17 '25 21:10

superus8r


Unfortunately, Appium UIAutomator2 does not support the property testTag yet.

There is an issue already created on Apppium's repository requesting this property.

like image 31
extmkv Avatar answered Oct 17 '25 22:10

extmkv