Automating Android Jetpack Compose app with Appium | by means of pedram pourzand | Nov, 2023

symbol from

Jetpack Compose is Android’s recommended trendy toolkit for establishing local person interfaces. It streamlines and expedites the method of UI building at the Android platform. With minimum code, tough equipment, and user-friendly Kotlin APIs, hastily breathe existence into your app.

How Jetpack Compose is other in UI design

Jetpack Compose, being a declarative UI framework for Android, Builders the use of Jetpack Compose don’t want to assign explicit IDs to UI components. essentially is determined by a tree construction of composable purposes to outline the UI hierarchy.

In Jetpack Compose, the state of the UI is decided by means of the composition of composable purposes and their parameters. Every composable serve as represents a node within the UI tree, and the framework mechanically manages the state and updates in response to adjustments within the underlying knowledge.

Boundaries of UiAutomator2 with Jetpack Compose

Compose does now not inherently supply solid identifiers for UI components. Automation equipment ceaselessly depend on distinctive identifiers (equivalent to useful resource IDs or accessibility IDs) to engage with components. With out solid identifiers, finding and interacting with explicit components in a Compose app may also be more difficult.

What are the choices to lacking ID in Compose?

Figuring out components in Compose UI may also be tricky, so builders ceaselessly depend on ‘Content material Descriptions’ to take action. Then again, overusing this system can negatively have an effect on accessibility. To facilitate checking out, Jetpack Compose has presented a semantic characteristic referred to as `testTag`. By way of assigning this characteristic to a node, it may be uniquely known all the way through checking out. Then again, it is very important be aware that UiAutomator2 and Appium don’t these days give a boost to the popularity of `testTag`.

modifier = Modifier
.semantics { contentDescription = "composeElement" },
Appium Inspector

Why Content material Description isn’t your best choice!

We don’t need to use `Content material Description` closely in our app. For customers with disabilities, content material descriptions are essential for more than a few accessibility products and services. Those products and services would possibly come with magnification gestures, spoken comments, and different assistive applied sciences that depend on textual knowledge to offer a significant person revel in.

Choice and technique to keep away from Content material Description

On this case, I attempted so as to add testTag for each and every part however as I discussed previous there’s no give a boost to for testTag in UiAutomator2 and the part seems with none testTag characteristic in Appium Inspector.

In Jetpack Compose, the semantics block is used to outline houses associated with the accessibility and semantics of person interface components. The particular characteristic `testTagsAsResourceId` is used to configure whether or not testTags must be handled as useful resource IDs. We added the syntax to the MainActivity.kt of the applying to make use of it project-wide

semantics { testTagsAsResourceId = true },

at the desired display upload testTag to the Modifier:

modifier = Modifier    
.semantics { testTag = "testTagAsRresourceId" },
now by means of development the app, I see the resource-id

Find out how to use resource-id in Check Automation

With all being mentioned and achieved, Appium nonetheless can’t have interaction with Component’s resource-id when the use of the Appium library click_element By way of.ID and offering resource-id because the part’s ID.

However the answer is to exchange your testTag (on your app code) bellow syntax so that you could have interaction with components the use of the ID as locator:

modifier = Modifier
.semantics { testTag = "android:identity/testTagRresourceId" },

Or supply resource-id as XPATH by means of the bellow syntax on your check automation code:

"//android.view.View[@resource-id= ‘testTagAsRresourceId’]"

You’ll at all times achieve out to my LinkedIn web page if there’s any query…

Leave a Reply

Your email address will not be published. Required fields are marked *