{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

AssertionsKt

public final class AssertionsKt


Summary

Public methods

static final @NonNull SemanticsNodeInteraction
assert(
    @NonNull SemanticsNodeInteraction receiver,
    @NonNull SemanticsMatcher matcher,
    Function0<@NonNull String> messagePrefixOnError
)

Asserts that the provided matcher is satisfied for this node.

static final @NonNull SemanticsNodeInteractionCollection

Asserts that all the nodes in this collection satisfy the given matcher.

static final @NonNull SemanticsNodeInteractionCollection

Asserts that this collection contains at least one element that satisfies the given matcher.

static final @NonNull SemanticsNodeInteraction
assertContentDescriptionContains(
    @NonNull SemanticsNodeInteraction receiver,
    @NonNull String value,
    boolean substring,
    boolean ignoreCase
)

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

static final @NonNull SemanticsNodeInteraction

Asserts that the node's content description contains exactly the given values and nothing else.

static final @NonNull SemanticsNodeInteractionCollection
assertCountEquals(
    @NonNull SemanticsNodeInteractionCollection receiver,
    int expectedSize
)

Asserts that this collection of nodes is equal to the given expectedSize.

static final @NonNull SemanticsNodeInteraction

Asserts that the current semantics node has a click action.

static final @NonNull SemanticsNodeInteraction

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

static final @NonNull SemanticsNodeInteraction

Asserts that the current semantics node is displayed on screen.

static final @NonNull SemanticsNodeInteraction

Asserts that the current semantics node is enabled.

static final @NonNull SemanticsNodeInteraction

Asserts that the current semantics node has a focus.

static final @NonNull SemanticsNodeInteraction

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

static final @NonNull SemanticsNodeInteraction

Asserts that the current semantics node is not enabled.

static final @NonNull SemanticsNodeInteraction

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

static final @NonNull SemanticsNodeInteraction

Asserts that the current semantics node is not selected.

static final @NonNull SemanticsNodeInteraction

Asserts that the current semantics node is unchecked.

static final @NonNull SemanticsNodeInteraction

Asserts that the current semantics node is checked.

static final @NonNull SemanticsNodeInteraction

Asserts that the current semantics node is selectable.

static final @NonNull SemanticsNodeInteraction

Asserts that the current semantics node is selected.

static final @NonNull SemanticsNodeInteraction

Asserts that the current semantics node is toggleable.

static final @NonNull SemanticsNodeInteraction

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

static final @NonNull SemanticsNodeInteraction
assertTextContains(
    @NonNull SemanticsNodeInteraction receiver,
    @NonNull String value,
    boolean substring,
    boolean ignoreCase
)

Asserts that the node's text contains the given value.

static final @NonNull SemanticsNodeInteraction
assertTextEquals(
    @NonNull SemanticsNodeInteraction receiver,
    @NonNull String values,
    boolean includeEditableText
)

Asserts that the node's text contains exactly the given values and nothing else.

static final @NonNull SemanticsNodeInteraction

Asserts the node's value equals the given value.

Public methods

assert

public static final @NonNull SemanticsNodeInteraction assert(
    @NonNull SemanticsNodeInteraction receiver,
    @NonNull SemanticsMatcher matcher,
    Function0<@NonNull String> messagePrefixOnError
)

Asserts that the provided matcher is satisfied for this node.

Parameters
@NonNull SemanticsMatcher matcher

Matcher to verify.

Function0<@NonNull String> messagePrefixOnError

Prefix to be put in front of an error that gets thrown in case this assert fails. This can be helpful in situations where this assert fails as part of a bigger operation that used this assert as a precondition check.

Throws
kotlin.AssertionError

if the matcher does not match or the node can no longer be found.

assertAll

public static final @NonNull SemanticsNodeInteractionCollection assertAll(
    @NonNull SemanticsNodeInteractionCollection receiver,
    @NonNull SemanticsMatcher matcher
)

Asserts that all the nodes in this collection satisfy the given matcher.

This passes also for empty collections.

Parameters
@NonNull SemanticsMatcher matcher

Matcher that has to be satisfied by all the nodes in the collection.

Throws
kotlin.AssertionError

if the collection contains at least one element that does not satisfy the given matcher.

assertAny

public static final @NonNull SemanticsNodeInteractionCollection assertAny(
    @NonNull SemanticsNodeInteractionCollection receiver,
    @NonNull SemanticsMatcher matcher
)

Asserts that this collection contains at least one element that satisfies the given matcher.

Parameters
@NonNull SemanticsMatcher matcher

Matcher that has to be satisfied by at least one of the nodes in the collection.

Throws
kotlin.AssertionError

if not at least one matching node was node.

assertContentDescriptionContains

public static final @NonNull SemanticsNodeInteraction assertContentDescriptionContains(
    @NonNull SemanticsNodeInteraction receiver,
    @NonNull String value,
    boolean substring,
    boolean ignoreCase
)

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

Note that in merged semantics tree there can be a list of content descriptions that got merged from the child nodes. Typically an accessibility tooling will decide based on its heuristics which ones to announce.

Throws AssertionError if the node's value does not contain value, or if the node has no value

Parameters
@NonNull String value

Value to match as one of the items in the list of content descriptions.

boolean substring

Whether this can be satisfied as a substring match of an item in the list of descriptions.

boolean ignoreCase

Whether case should be ignored.

assertContentDescriptionEquals

public static final @NonNull SemanticsNodeInteraction assertContentDescriptionEquals(
    @NonNull SemanticsNodeInteraction receiver,
    @NonNull String values
)

Asserts that the node's content description contains exactly the given values and nothing else.

Note that in merged semantics tree there can be a list of content descriptions that got merged from the child nodes. Typically an accessibility tooling will decide based on its heuristics which ones to announce.

Throws AssertionError if the node's descriptions don't contain all items from values, or if the descriptions contain extra items that are not in values.

Parameters
@NonNull String values

List of values to match (the order does not matter)

assertCountEquals

public static final @NonNull SemanticsNodeInteractionCollection assertCountEquals(
    @NonNull SemanticsNodeInteractionCollection receiver,
    int expectedSize
)

Asserts that this collection of nodes is equal to the given expectedSize.

Provides a detailed error message on failure.

Throws
kotlin.AssertionError

if the size is not equal to expectedSize

assertHasClickAction

public static final @NonNull SemanticsNodeInteraction assertHasClickAction(@NonNull SemanticsNodeInteraction receiver)

Asserts that the current semantics node has a click action.

Throws AssertionError if the node is doesn't have a click action.

assertHasNoClickAction

public static final @NonNull SemanticsNodeInteraction assertHasNoClickAction(@NonNull SemanticsNodeInteraction receiver)

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

Throws AssertionError if the node has a click action.

assertIsDisplayed

public static final @NonNull SemanticsNodeInteraction assertIsDisplayed(@NonNull SemanticsNodeInteraction receiver)

Asserts that the current semantics node is displayed on screen.

Throws AssertionError if the node is not displayed.

assertIsEnabled

public static final @NonNull SemanticsNodeInteraction assertIsEnabled(@NonNull SemanticsNodeInteraction receiver)

Asserts that the current semantics node is enabled.

Throws AssertionError if the node is not enabled or does not define the property at all.

assertIsFocused

public static final @NonNull SemanticsNodeInteraction assertIsFocused(@NonNull SemanticsNodeInteraction receiver)

Asserts that the current semantics node has a focus.

Throws AssertionError if the node is not in the focus or does not defined the property at all.

assertIsNotDisplayed

public static final @NonNull SemanticsNodeInteraction assertIsNotDisplayed(@NonNull SemanticsNodeInteraction receiver)

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

Throws AssertionError if the node is displayed.

assertIsNotEnabled

public static final @NonNull SemanticsNodeInteraction assertIsNotEnabled(@NonNull SemanticsNodeInteraction receiver)

Asserts that the current semantics node is not enabled.

Throws AssertionError if the node is enabled or does not defined the property at all.

assertIsNotFocused

public static final @NonNull SemanticsNodeInteraction assertIsNotFocused(@NonNull SemanticsNodeInteraction receiver)

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

Throws AssertionError if the node is in the focus or does not defined the property at all.

assertIsNotSelected

public static final @NonNull SemanticsNodeInteraction assertIsNotSelected(@NonNull SemanticsNodeInteraction receiver)

Asserts that the current semantics node is not selected.

Throws AssertionError if the node is selected or not selectable.

assertIsOff

public static final @NonNull SemanticsNodeInteraction assertIsOff(@NonNull SemanticsNodeInteraction receiver)

Asserts that the current semantics node is unchecked.

Throws AssertionError if the node is checked, indeterminate, or not toggleable.

assertIsOn

public static final @NonNull SemanticsNodeInteraction assertIsOn(@NonNull SemanticsNodeInteraction receiver)

Asserts that the current semantics node is checked.

Throws AssertionError if the node is not unchecked, indeterminate, or not toggleable.

assertIsSelectable

public static final @NonNull SemanticsNodeInteraction assertIsSelectable(@NonNull SemanticsNodeInteraction receiver)

Asserts that the current semantics node is selectable.

Throws AssertionError if the node is not selectable.

assertIsSelected

public static final @NonNull SemanticsNodeInteraction assertIsSelected(@NonNull SemanticsNodeInteraction receiver)

Asserts that the current semantics node is selected.

Throws AssertionError if the node is unselected or not selectable.

assertIsToggleable

public static final @NonNull SemanticsNodeInteraction assertIsToggleable(@NonNull SemanticsNodeInteraction receiver)

Asserts that the current semantics node is toggleable.

Throws AssertionError if the node is not toggleable.

assertRangeInfoEquals

public static final @NonNull SemanticsNodeInteraction assertRangeInfoEquals(
    @NonNull SemanticsNodeInteraction receiver,
    @NonNull ProgressBarRangeInfo value
)

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

For further details please check SemanticsProperties.ProgressBarRangeInfo. Throws AssertionError if the node's value is not equal to value, or if the node has no value

assertTextContains

public static final @NonNull SemanticsNodeInteraction assertTextContains(
    @NonNull SemanticsNodeInteraction receiver,
    @NonNull String value,
    boolean substring,
    boolean ignoreCase
)

Asserts that the node's text contains the given value.

This will also search in SemanticsProperties.EditableText.

Note that in merged semantics tree there can be a list of text items that got merged from the child nodes. Typically an accessibility tooling will decide based on its heuristics which ones to use.

Throws AssertionError if the node's value does not contain value, or if the node has no value

Parameters
@NonNull String value

Value to match as one of the items in the list of text values.

boolean substring

Whether this can be satisfied as a substring match of an item in the list of text.

boolean ignoreCase

Whether case should be ignored.

See also
Text

assertTextEquals

public static final @NonNull SemanticsNodeInteraction assertTextEquals(
    @NonNull SemanticsNodeInteraction receiver,
    @NonNull String values,
    boolean includeEditableText
)

Asserts that the node's text contains exactly the given values and nothing else.

This will also search in SemanticsProperties.EditableText by default.

Note that in merged semantics tree there can be a list of text items that got merged from the child nodes. Typically an accessibility tooling will decide based on its heuristics which ones to use.

Throws AssertionError if the node's text values don't contain all items from values, or if the text values contain extra items that are not in values.

Parameters
@NonNull String values

List of values to match (the order does not matter)

boolean includeEditableText

Whether to also assert against the editable text.

assertValueEquals

public static final @NonNull SemanticsNodeInteraction assertValueEquals(
    @NonNull SemanticsNodeInteraction receiver,
    @NonNull String value
)

Asserts the node's value equals the given value.

For further details please check SemanticsProperties.StateDescription. Throws AssertionError if the node's value is not equal to value, or if the node has no value