4

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

Sathis Kumar
  • 69
  • 1
  • 4

3 Answers3

2

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
superus8r
  • 751
  • 1
  • 11
  • 24
1

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

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

extmkv
  • 1,991
  • 1
  • 18
  • 36
0

Fellas, I just managed to access Compose elements by simply adding property contentDescription = "UseThisInstead" in Android Studio later on i could access the element with Appium/ UIAutomator2 by xpath

driver.findElement(By.xpath("//*[@content-desc='UseThisInstead']")).isDisplayed();

try that