Function

onRootWithViewInteraction

Scopes the Compose interaction to the View hierarchy matched by the provided Espresso ViewInteraction.

onRootWithViewInteractionBasicSample

fun onRootWithViewInteractionBasicSample() {
    // Select the "Header" View container
    val headerInteraction = onView(withId(header_id))
    // Scope the Compose interaction to only the Header
    composeTestRule
        .onRootWithViewInteraction(headerInteraction)
        .onNodeWithContentDescription("Settings")
        .performClick()
}

onRootWithViewInteractionFragmentSample

fun onRootWithViewInteractionFragmentSample() {
    // Select the container for the Detail Fragment
    val detailContainerInteraction = onView(withId(detail_fragment_container_id))
    // Assert that the submit button exists/is enabled only in the detail fragment
    composeTestRule
        .onRootWithViewInteraction(detailContainerInteraction)
        .onNodeWithText("Submit")
        .assertIsEnabled()
}

onRootWithViewInteractionRecyclerViewSample

fun onRootWithViewInteractionRecyclerViewSample() {
    // Select the specific View row containing "Item #5"
    val specificRowInteraction =
        onView(allOf(withId(recycler_item_root_id), hasDescendant(withText("Item #5"))))
    // Scope interaction to that specific row View
    composeTestRule
        .onRootWithViewInteraction(specificRowInteraction)
        .onNodeWithTag("fav_icon")
        .assertIsDisplayed()
        .performClick()
}

Last updated: