question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Android] Testing Compose layout

See original GitHub issue

The problem

I haven’t checked well yet, but maybe do we need something in espresso driver? https://developer.android.com/jetpack/compose/testing


Update: Espresso driver https://github.com/appium/appium-espresso-driver is getting compse support. UIA2 driver cannot support it because of technical differences.


Updated


Updated

  • UIA2 driver also can find a compose element if the element had testTagsAsResourceId . You can access to the element as resource-id.
    • Appium 1 can access to these elements via XPath https://github.com/appium/appium/issues/15138#issuecomment-1127658653 (since the version autocomplete its package name as valid resource-id rule.)
    • disableIdLocatorAutocompletion settings api helps to disable package name autocomplete in case you set an arbitrary name as the testTagsAsResourceId, without the package name in compose.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:30
  • Comments:64 (24 by maintainers)

github_iconTop GitHub Comments

17reactions
omar-leyvacommented, Jan 27, 2022

Google updated their AccessibilityNodeInfo to include testTag in the AccessibilityNodeInfo.extras object starting in compose UI 1.1.0-beta01. https://android-review.googlesource.com/c/platform/frameworks/support/+/1853077

Is this something that can be used to expose testTag in UIA2?

13reactions
davidgalindocommented, Jul 29, 2021

My company’s QA team is making extensive use of Appium for their automated tests. I recently wrote a few sections of our app using Jetpack Compose, and QA has stated that it has completely broken the tests that deal with UI generated with Compose. They are unable to find any views by using their resource ID or content description. Apparently when I set a content description on a view using Modifier.semantics{ contentDescription = "my ID" }, QA is unable to focus in on the exact view. For example, take this piece of code:

        OutlinedTextField(
            email,
            modifier = Modifier
                .fillMaxWidth()
                .layoutId(R.id.textInputEmail)
                .semantics { contentDescription = getString(R.string.sign_in_email_input) }
                .padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 4.dp),
            onValueChange = { email = it },
            label = { Text(getString(R.string.email)) },
        )

QA is only able to see this: Screen Shot 2021-07-29 at 9 56 54 AM Note that the content description is on a subview, not on the editText itself. The layoutId doesn’t help much, either.

Compose just hit its release version yesterday, and as a developer it is so much easier to work with than the declarative XML approach. We need Appium to work with compose since, in my opinion, the benefits to using Compose over XML are far too great. I appreciate the Appium team’s quick attention to this matter 😄

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing your Compose layout - Jetpack - Android Developers
Compose provides a set of testing APIs to find elements, verify their attributes and perform user actions. They also include advanced features such...
Read more >
Test Your Jetpack Compose Layout - Medium
Use composeTestRule when you need to test a compose layout in an empty activity to freely customize your layout state. And use androidComposeTestRule...
Read more >
UI Testing - Jetpack Compose Playground
When you can't find a Composable by a text and you want to make it detectable in your test. Jetpack Compose offers the...
Read more >
Getting started with testing Jetpack Compose - Bitrise Blog
Because Jetpack Compose is an instrumentation test, you can use a test framework such as Espresso, but Compose already provides a set of...
Read more >
How to test Jetpack Compose UI - Dmytro Shuba
Composable instead of View. · Compose Layout doesn't have IDs and tags. · Different testing tools. · Compose tests are synchronized by default....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found