Class

SemanticsNodeInteraction

Represents a semantics node and the path to fetch it from the semantics tree.

clickAndVerifyCheckbox

@Sampled
fun clickAndVerifyCheckbox() {
    composeTestRule.onNode(isToggleable()).performClick().assertIsOn()
}

useUnmergedTree

@Sampled
fun useUnmergedTree() {
    composeTestRule.setContent {
        // Box is a semantically merging composable. All testTags of its
        // children are merged up into it in the merged semantics tree.
        Box(Modifier.testTag("box").padding(16.dp)) { Box(Modifier.testTag("icon").size(48.dp)) }
    }

    // Verify the position of the inner box. Without `useUnmergedTree`, the
    // test would check the position of the outer box (which is `(0, 0)`)
    // instead of the position of the inner box (which is `(16, 16)`).
    composeTestRule
        .onNodeWithTag("icon", useUnmergedTree = true)
        .assertLeftPositionInRootIsEqualTo(16.dp)
        .assertTopPositionInRootIsEqualTo(16.dp)
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: