Unlike sample here which produces single semantics which makes it impossible to test nodes with multiple drawable ids. Following allows producing and testing multiple semantics of same type in a tree.
Usage in compose:
Modifier.semantics { drawableId = R.drawable.baseline_call_made_24 }
Modifier.semantics { drawableUrl = avatar ?: "" }
Produces tree:
Node #1
|-Node #4
...
|-Node #9
| DrawableUrl = '[https://placekitten.com/200/100, https://placekitten.com/200/200]'
| DrawableResId = '[2131230723, 2131230722]'
...
Test:
composeTestRule
.onNode(SemanticsMatcher.keyIsDefined(SemanticsProperties.CollectionInfo))
.onChildAt(1)
.assert(
hasDrawable(target1.avatar) and
hasText(target1.cover) and
hasDrawable(R.drawable.baseline_call_made_24) and
hasDrawable(R.drawable.baseline_call_24)
)
.assertIsDisplayed()