6월 3일의 ⁠#Android11: 베타 버전 출시 행사에 참여하세요.

SemanticsNodeInteraction

class SemanticsNodeInteraction
kotlin.Any
   ↳ androidx.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 doClick, assertions such as assertHasClickAction, or navigate to other nodes such as children.

This is usually obtained from methods like findByTag, find.

Example usage:

findByTag("myCheckbox")
   .doClick()
   .assertIsOn()

Summary

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.ui.test
SemanticsNodeInteractionCollection

Returns all the ancestors of this node.

SemanticsNodeInteraction
SemanticsNodeInteraction.assert(matcher: SemanticsMatcher, messagePrefixOnError: () -> String = null)

Asserts that the provided matcher is satisfied for this node.

SemanticsNodeInteraction

Asserts that the current component has a click action.

SemanticsNodeInteraction

Asserts that the current component doesn't have a click action.

SemanticsNodeInteraction

Asserts that the current component is displayed on screen.

SemanticsNodeInteraction

Asserts that the current component is enabled.

SemanticsNodeInteraction

Asserts that the current component has hidden property set to true.

SemanticsNodeInteraction

Asserts the component is in a mutually exclusive group.

SemanticsNodeInteraction

Asserts that the current component is not displayed on screen.

SemanticsNodeInteraction

Asserts that the current component is not enabled.

SemanticsNodeInteraction

Asserts that the current component has hidden property set to false.

SemanticsNodeInteraction

Asserts that the current component is unchecked.

SemanticsNodeInteraction

Asserts that the current component is checked.

SemanticsNodeInteraction

Asserts that the current component is selectable.

SemanticsNodeInteraction

Asserts that the current component is selected.

SemanticsNodeInteraction

Asserts that the current component is toggleable.

SemanticsNodeInteraction

Asserts that the current component is unselected.

SemanticsNodeInteraction

Asserts the component's label equals the given String.

SemanticsNodeInteraction

Asserts the component's range info equals the given value.

SemanticsNodeInteraction

Asserts the component's value equals the given value.

Unit

Provides support to call custom semantics actions on this node.

Unit

Provides support to call custom semantics actions on this node.

Bitmap

Captures the underlying component's surface into bitmap.

SemanticsNodeInteraction

Returns exactly one child of this node.

SemanticsNodeInteraction

Returns child of this node at the given index.

SemanticsNodeInteractionCollection

Returns children of this node.

Unit
SemanticsNodeInteraction.doClearText(alreadyHasFocus: Boolean = false)

Clears the text in this node in similar way to IME.

SemanticsNodeInteraction

Performs a click action on the given component.

SemanticsNodeInteraction

Executes the gestures specified in the given block.

SemanticsNodeInteraction

Executes the (partial) gesture specified in the given block.

Unit
SemanticsNodeInteraction.doReplaceText(text: String, alreadyHasFocus: Boolean = false)

Replaces existing text with the given text in this node in similar way to IME.

SemanticsNodeInteraction

Scrolls to a component using SemanticsActions.

Unit
SemanticsNodeInteraction.doSendImeAction(alreadyHasFocus: Boolean = false)

Sends to this node the IME action associated with it in similar way to IME.

Unit
SemanticsNodeInteraction.doSendText(text: String, alreadyHasFocus: Boolean = false)

Sends the given text to this node in similar way to IME.

String

Dumps all the semantics nodes information it holds into string.

SemanticsNodeInteraction

Returns a parent of this node.

SemanticsNodeInteraction

Returns exactly one sibling of this node.

SemanticsNodeInteractionCollection

Returns all siblings of this node.

Public methods

assertDoesNotExist

fun assertDoesNotExist(): Unit

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.

Exceptions
AssertionError if the assert fails.

assertExists

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: String? = null 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.".
Exceptions
AssertionError if the assert fails.

fetchSemanticsNode

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.

Exceptions
AssertionError if 0 or multiple nodes found.