The second Android 11 Developer Preview is now available, test it out and share your feedback.

SemanticsNodeInteraction

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

Represents a component with which one can interact with the hierarchy. Examples of interactions include findByTag, isToggleable, assertIsOn, doClick

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
SemanticsNodeInteraction

Asserts that the provided predicate 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 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 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 that the semantics of the component are the same as the given semantics.

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

Performs a click action on the given component.

SemanticsNodeInteraction

Executes the gestures specified in the given block.

SemanticsNodeInteraction

Scrolls to a component using SemanticsActions.

String

Dumps all the semantics nodes information it holds into string.

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.