I’m starting to make UI tests for my app. In order to probe certain parts of the screen, there’s a suite of onNode*
functions that come with the ComposeRule
. In particular, there’s onNodeWithContentDescription
which will try to find elements with a specific contentDescription
value. Some stuff like Icon
expose this in their constructor, but there’s also the modifier Modifier.semantics {this.contentDescription = "desc"}
that could be applied to any composable.
I’m aware of the testTag
modifier, but that only serves a role for testing. By the looks of it, contentDescription
could serve the same purpose while also contributing to others (accessibility services in this case). I’m not familiar with any accessibility features as I don’t need them, but I was wondering if plastering this modifier on all of the UI elements I want to easily grab for testing would pose a problem?
Use cases
I have 2 elements that are essentially identical to one another given what’s available from the has*
matchers. Giving them different contentDescription
s will distinguish them. I figure accessibility services will work fine with these.
I also have 2 icon elements that are meant to overlap one another to avoid the need for me to create a copy of the one with less content in it just to make the one with the additional content. Since both could be on the screen at some point, would them having different contentDescription
s cause accessibility services to create some confusion in some way? I suspect stateDescription
should be better here (they’re already together in a Box
)?