Android 12 Developer Preview is here! Try it out, and give us your feedback!

SemanticsNodeInteraction

class SemanticsNodeInteraction
kotlin.Any
   ↳ androidx.compose.ui.test.SemanticsNodeInteraction

Represents a semantics node and the path to fetch it from the semantics tree. One can interact with this node by performing actions such as performClick, assertions such as assertHasClickAction, or navigate to other nodes such as onChildren.

This is usually obtained from methods like onNode.

Example usage:

composeTestRule.onNodeWithTag("myCheckbox")
   .performClick()
   .assertIsOn()

useUnmergedTree is for tests with a special need to inspect "implementation detail" children. For example:

composeTestRule.setMaterialContent {
    // IconButton is a semantically merging composable.  All testTags of its children
    // are merged up into it in the default, "merged" semantics tree.
    IconButton(onClick = {}) {
        MyIcon(Modifier.testTag("icon"))
    }
}

// Assert that MyIcon is at the expected position inside the IconButton.
// Without useUnmergedTree, then the test would check the position of the IconButton (0, 0)
// instead of the position of the Icon (30, 30).
composeTestRule.onNodeWithTag("icon", useUnmergedTree = true)
    .assertLeftPosition(30.dp)
    .assertTopPosition(30.dp)

Summary

Public constructors
<init>(testContext: TestContext, useUnmergedTree: Boolean, matcher: SemanticsMatcher)

<init>(testContext: TestContext, useUnmergedTree: Boolean, selector: SemanticsSelector)

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

Public methods
Unit

Asserts that no item was found or that the item is no longer in the hierarchy.

SemanticsNodeInteraction
assertExists(errorMessageOnFail: String? = null)

Asserts that the component was found and is part of the component tree.

SemanticsNode
fetchSemanticsNode(errorMessageOnFail: String? = null)

Returns the semantics node captured by this object.

Extension functions
From androidx.compose.ui.test
SemanticsNodeInteraction
SemanticsNodeInteraction.assert(matcher: SemanticsMatcher, messagePrefixOnError: () -> String = null)

Asserts that the provided matcher is satisfied for this node.

SemanticsNodeInteraction

Asserts that the node's content description contains the given value as a substring.

SemanticsNodeInteraction

Asserts that the node's content description equals the given value.

SemanticsNodeInteraction

Asserts that the current semantics node has a click action.

SemanticsNodeInteraction

Asserts that the current semantics node has doesn't have a click action.

SemanticsNodeInteraction

Asserts that the layout of this node has height that is greater ot equal to expectedMinHeight.

SemanticsNodeInteraction

Asserts that the layout of this node has height equal to expectedHeight.

SemanticsNodeInteraction

Asserts that the current semantics node is displayed on screen.

SemanticsNodeInteraction

Asserts that the current semantics node is enabled.

SemanticsNodeInteraction

Asserts that the current semantics node has a focus.

SemanticsNodeInteraction

Asserts that the current semantics node is not displayed on screen.

SemanticsNodeInteraction

Asserts that the current semantics node is not enabled.

SemanticsNodeInteraction

Asserts that the current semantics node does not have a focus.

SemanticsNodeInteraction

Asserts that the current semantics node is not selected.

SemanticsNodeInteraction

Asserts that the current semantics node is unchecked.

SemanticsNodeInteraction

Asserts that the current semantics node is checked.

SemanticsNodeInteraction

Asserts that the current semantics node is selectable.

SemanticsNodeInteraction