SemanticsNodeInteraction
class SemanticsNodeInteraction
constructor(
internal val testContext: TestContext,
internal val useUnmergedTree: Boolean,
internal val selector: SemanticsSelector,
)
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
.
An instance of SemanticsNodeInteraction
can be obtained from
onNode
and convenience methods that use a specific
filter, such as onNodeWithText
.
Here you can see how you can locate a checkbox, click it and verify that it's checked:
useUnmergedTree
is for tests with a special need to inspect implementation detail within
children. For example:
Secondary Constructors
constructor(
testContext: TestContext,
useUnmergedTree: Boolean,
matcher: SemanticsMatcher,
) : this(testContext, useUnmergedTree, SemanticsSelector(matcher))
Functions
fun fetchSemanticsNode(errorMessageOnFail: String? = null): SemanticsNode
Returns the semantics node captured by this object.
Note: Accessing this object involves synchronization with your UI. If you are accessing this multiple times in one atomic operation, it is better to cache the result instead of calling this API multiple times.
This will fail if there is 0 or multiple nodes matching.
fun assertDoesNotExist()
Asserts that no item was found or that the item is no longer in the hierarchy.
This will synchronize with the UI and fetch all the nodes again to ensure it has latest data.
fun assertExists(errorMessageOnFail: String? = null): SemanticsNodeInteraction
Asserts that the component was found and is part of the component tree.
This will synchronize with the UI and fetch all the nodes again to ensure it has latest data.
If you are using fetchSemanticsNode
you don't need to call this. In fact you would just
introduce additional overhead.
Parameters
errorMessageOnFail | Error message prefix to be added to the message in case this asserts fails. This is typically used by operations that rely on this assert. Example prefix could be: "Failed to perform doOnClick.". |
fun assertIsDeactivated(errorMessageOnFail: String? = null)
Asserts that the component was found and it is deactivated.
For example, the children of androidx.compose.ui.layout.SubcomposeLayout
which are retained
to be reused in future are considered deactivated.