Has anyone encountered an issue when UI testing co...
# compose-android
t
Has anyone encountered an issue when UI testing compose - where applying multiple
testTag
to the same modifier means that
onNodeWithTag
fails for subsequent test tags? e.g.
Copy code
fun RootScreen() {
    SomeScreen(modifier = Modifier.semantics { testTag = "tag_a" }
}

fun SomeScreen(modifier: Modifier) {
    Scaffold (modifier = modifier.semantics { testTag = "test_b" }) { ...
}
A test with
onNodeWithTag("test_b")
fails. But if I remove
tag_a
, it succeeds.
It makes no difference whether I
useUnmergedTree
or not
Looking at the
SemanticsProperties
code:
Copy code
val TestTag = SemanticsPropertyKey<String>(
    name = "TestTag",
    mergePolicy = { parentValue, _ ->
        // Never merge TestTags, to avoid leaking internal test tags to parents.
        parentValue
    }
)
It’s interesting, the ‘merge policy’ seems to say ‘only ever use the parent value’ I’m going to guess that means if there’s a conflict when adding a tag, then the tag is ignored and the original tag is retained