이제 Android 11 개발자 프리뷰를 사용할 수 있습니다. 테스트해 보고 의견을 공유하세요.

androidx.ui.test

Classes

AnimationClockTestRule

A TestRule to monitor and take over the animation clock in the composition.

CollectedSizes

Small utility class to provide convenient assertion for width and height for some PxSize.

DisableTransitions

This rule will disable all Transition animations for the test.

GestureScope

An object that has an associated component in which one can inject gestures.

SemanticsNodeInteraction

Represents a component with which one can interact with the hierarchy.

SemanticsPredicate

Wrapper for semantics predicate that allows to build string explaining to the developer what conditions were being performed.

Top-level functions summary

T
T.assertCountEquals(expectedSize: Int)

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

ComposeTestRule
createComposeRule(disableTransitions: Boolean = false)

Factory method to provide implementation of ComposeTestRule.

SemanticsConfiguration
createFullSemantics(isEnabled: Boolean? = null, value: String? = null, toggleableState: ToggleableState? = null, inMutuallyExclusiveGroup: Boolean? = null, isSelected: Boolean? = null)

Ensures the created SemanticsConfiguration object doesn't have any default values set.

SemanticsNodeInteraction

Finds a component that matches the given condition.

List<SemanticsNodeInteraction>

Finds all components that match the given condition.

List<SemanticsNodeInteraction>
findAllByTag(testTag: String)

Finds all components identified by the given tag.

List<SemanticsNodeInteraction>
findAllByText(text: String, ignoreCase: Boolean = false)

Finds all components with the given text as their accessibility label.

SemanticsNodeInteraction
findBySubstring(text: String, ignoreCase: Boolean = false)

Finds a component with accessibilityLabel that contains the given substring.

SemanticsNodeInteraction
findByTag(testTag: String)

Finds a component identified by the given tag.

SemanticsNodeInteraction
findByText(text: String, ignoreCase: Boolean = false)

Finds a component with the given text as its accessibilityLabel.

SemanticsPredicate

Returns whether the component has at least one ancestor that satisfies the given predicate.

SemanticsPredicate

Returns whether the component has at least one child that satisfies the given predicate.

SemanticsPredicate

Returns whether the component has at least one descendant that satisfies the given predicate.

SemanticsPredicate

Returns whether the component has at least one sibling that satisfies the given predicate.

SemanticsPredicate

Return whether the component has a semantics click action defined.

SemanticsPredicate

Return whether the component has no semantics click action defined.

SemanticsPredicate

Return whether the component has no semantics scrollable action defined.

SemanticsPredicate

Returns whether the component's parent satisfies the given predicate.

SemanticsPredicate

Return whether the component has a semantics scrollable action defined.

SemanticsPredicate
hasSubstring(substring: String, ignoreCase: Boolean = false)

Returns whether the component's label contains the given substring.

SemanticsPredicate
hasTestTag(testTag: String)

Returns whether the component is annotated by the given test tag.

SemanticsPredicate
hasText(text: String, ignoreCase: Boolean = false)

Returns whether the component's label matches exactly to the given text.

SemanticsPredicate
hasValue(value: String)

Returns whether the component's value matches exactly to the given accessibility value.

SemanticsPredicate

Returns whether the component is hidden.

SemanticsPredicate

Verifies that the component is in a mutually exclusive group - that is, that FoundationSemanticsProperties.InMutuallyExclusiveGroup is set to true

SemanticsPredicate

Returns whether the component is not hidden.

SemanticsPredicate

Returns whether the component is not toggled.

SemanticsPredicate

Returns whether the component is toggled.

SemanticsPredicate

Return whether the component is selectable.

SemanticsPredicate

Returns whether the component is selected.

SemanticsPredicate

Return whether the component is checkable.

SemanticsPredicate

Returns whether the component is not selected.

Top-level properties summary

DpConstraints

Constant to emulate very big but finite constraints

Extension functions summary

For android.graphics.Bitmap
Unit
Bitmap.assertPixelColor(expected: Color, x: Int, y: Int, error: (Color) -> String = { color -> "Pixel($x, $y) expected to be $expected, but was $color" })

Asserts that the color at a specific pixel in the bitmap at (x, y) is expected.

Unit
Bitmap.assertPixels(expectedSize: IntPxSize? = null, expectedColorProvider: (pos: IntPxPosition) -> Color?)

A helper function to run asserts on Bitmap.

Unit
Bitmap.assertShape(density: Density, shape: Shape, shapeColor: Color, backgroundColor: Color, backgroundShape: Shape = RectangleShape, sizeX: Px = width.toFloat().px, sizeY: Px = height.toFloat().px, shapeSizeX: Px = sizeX, shapeSizeY: Px = sizeY, centerX: Px = width.px / 2f, centerY: Px = height.px / 2f, shapeOverlapPixelCount: Px = 1.px)

Asserts that the given shape is drawn within the bitmap with the size the dimensions shapeSizeX x shapeSizeY, centered at (centerX, centerY) with the color shapeColor.

For android.view.View
Bitmap

Captures the underlying view's surface into bitmap.

For kotlin.collections.Collection
String

Dumps all the semantics nodes information it holds into string.

For SemanticsNodeInteraction
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.

For SemanticsConfiguration
Unit

SemanticsConfiguration

Returns a (mutated) copy of the original SemanticsConfiguration object.

For ComposeExecutionControl
Unit

Performs recomposition and asserts that there were some pending changes.

Unit

Asserts that last recomposition had some changes.

Unit

Asserts that last recomposition had no some changes.

Unit

Assert that the underlying view under test has a positive size.

Unit

Performs recomposition and asserts that there were some pending changes.

Unit

Performs the given amount of frames and asserts that there are no changes pending afterwards.

Int

Runs frames until there are no changes pending.

Unit

Performs recomposition and asserts that there were some pending changes.

For GestureScope
PxPosition

Transforms the position to global coordinates, as defined by globalBounds

Unit

Performs a click gesture on the given position on the associated component.

Unit

Performs a click gesture on the associated component.

Unit

Performs a double click gesture on the given position on the associated component.

Unit

Performs a double click gesture on the associated component.

Unit

Performs a long click gesture on the given position on the associated component.

Unit

Performs a long click gesture on the middle of the associated component.

Unit
GestureScope.sendSwipe(start: PxPosition, end: PxPosition, duration: Duration = 200.milliseconds)

Performs the swipe gesture on the associated component.

Unit

Performs a swipe down gesture on the associated component.

Unit

Performs a swipe left gesture on the associated component.

Unit

Performs a swipe right gesture on the associated component.

Unit

Performs a swipe up gesture on the associated component.

Unit
GestureScope.sendSwipeWithVelocity(start: PxPosition, end: PxPosition, endVelocity: Float, duration: Duration = 200.milliseconds)

Performs the swipe gesture on the associated component, such that the velocity when the gesture is finished is roughly equal to endVelocity.

For ComposeTestRule
CollectedSizes
ComposeTestRule.setContentAndCollectSizes(parentConstraints: DpConstraints = BigTestConstraints, children: () -> Unit)

Set content as with ComposeTestRule.setContent, but return CollectedSizes to assert width and height of this content

PxSize
ComposeTestRule.setContentAndGetPixelSize(parentConstraints: DpConstraints = BigTestConstraints, performSetContent: (() -> Unit) -> Unit = { setContent(it) }, children: () -> Unit)

Set content as with ComposeTestRule.setContent, but return sizes of this content

For ComposeBenchmarkScope
Unit

Sets up the content.

Extension properties summary

For GestureScope
PxPosition

Returns the center of the component we're interacting with, in the component's local coordinate system, where (0.

PxBounds

Returns the global bounds of the component we're interacting with

IntPxSize

Returns the size of the component we're interacting with

For LayoutCoordinates
PxPosition

Returns the position relative to the parent Layout

Top-level functions

assertCountEquals

fun <T : Collection<SemanticsNodeInteraction>> T.assertCountEquals(expectedSize: Int): T

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

Provides a detailed error message on failure.

Exceptions
AssertionError if the size is not equal to expectedSize

createComposeRule

fun createComposeRule(disableTransitions: Boolean = false): ComposeTestRule

Factory method to provide implementation of ComposeTestRule.

This method is useful for tests in compose libraries where no custom Activity is usually needed. For app tests or launching custom activities, see AndroidComposeTestRule.

For Android this will use the default Activity (android.app.Activity). You need to add a reference to this activity into the manifest file of the corresponding tests (usually in androidTest/AndroidManifest.xml).

createFullSemantics

fun createFullSemantics(
    isEnabled: Boolean? = null,
    value: String? = null,
    toggleableState: ToggleableState? = null,
    inMutuallyExclusiveGroup: Boolean? = null,
    isSelected: Boolean? = null
): SemanticsConfiguration

Ensures the created SemanticsConfiguration object doesn't have any default values set. This intentionally enforces choosing every value in order to minimise possible unwanted side effects. Should be used to create initial default semantics for composables and afterwards SemanticsConfiguration.copyWith should be used to create a modified copy.

find

fun find(selector: SemanticsPredicate): SemanticsNodeInteraction

Finds a component that matches the given condition. This tries to match exactly one element and throws AssertionError if more than one is matched.

For usage patterns see SemanticsNodeInteraction

See Also

findAll

fun findAll(selector: SemanticsPredicate): List<SemanticsNodeInteraction>

Finds all components that match the given condition.

If you are working with elements that are not supposed to occur multiple times use find instead.

See Also

findAllByTag

fun findAllByTag(testTag: String): List<SemanticsNodeInteraction>

Finds all components identified by the given tag.

For usage patterns see SemanticsNodeInteraction

findAllByText

fun findAllByText(
    text: String,
    ignoreCase: Boolean = false
): List<SemanticsNodeInteraction>

Finds all components with the given text as their accessibility label.

For usage patterns see SemanticsNodeInteraction

findBySubstring

fun findBySubstring(
    text: String,
    ignoreCase: Boolean = false
): SemanticsNodeInteraction

Finds a component with accessibilityLabel that contains the given substring.

For usage patterns see SemanticsNodeInteraction

See Also

findByTag

fun findByTag(testTag: String): SemanticsNodeInteraction

Finds a component identified by the given tag.

For usage patterns see SemanticsNodeInteraction

findByText

fun findByText(
    text: String,
    ignoreCase: Boolean = false
): SemanticsNodeInteraction

Finds a component with the given text as its accessibilityLabel.

For usage patterns see SemanticsNodeInteraction

See Also

hasAnyAncestorThat

fun hasAnyAncestorThat(predicate: SemanticsPredicate): SemanticsPredicate

Returns whether the component has at least one ancestor that satisfies the given predicate.

Example: For the following tree |-X |-A |-B |-C1 |-C2 In case of C1, we would check the predicate against A and B

hasAnyChildThat

fun hasAnyChildThat(predicate: SemanticsPredicate): SemanticsPredicate

Returns whether the component has at least one child that satisfies the given predicate.

hasAnyDescendantThat

fun hasAnyDescendantThat(predicate: SemanticsPredicate): SemanticsPredicate

Returns whether the component has at least one descendant that satisfies the given predicate.

Example: For the following tree |-X |-A |-B |-C1 |-C2 In case of A, we would check the predicate against B,C1 and C2

hasAnySiblingThat

fun hasAnySiblingThat(predicate: SemanticsPredicate): SemanticsPredicate

Returns whether the component has at least one sibling that satisfies the given predicate.

Sibling is defined as a any other node that shares the same parent.

hasClickAction

fun hasClickAction(): SemanticsPredicate

Return whether the component has a semantics click action defined.

hasNoClickAction

fun hasNoClickAction(): SemanticsPredicate

Return whether the component has no semantics click action defined.

hasNoScrollAction

fun hasNoScrollAction(): SemanticsPredicate

Return whether the component has no semantics scrollable action defined.

hasParentThat

fun hasParentThat(predicate: SemanticsPredicate): SemanticsPredicate

Returns whether the component's parent satisfies the given predicate.

Returns false if no parent exists.

hasScrollAction

fun hasScrollAction(): SemanticsPredicate

Return whether the component has a semantics scrollable action defined.

hasSubstring

fun hasSubstring(
    substring: String,
    ignoreCase: Boolean = false
): SemanticsPredicate

Returns whether the component's label contains the given substring.

Parameters
substring: String Substring to check.
ignoreCase: Boolean = false Whether case should be ignored.

hasTestTag

fun hasTestTag(testTag: String): SemanticsPredicate

Returns whether the component is annotated by the given test tag.

Parameters
testTag: String Value to match.

hasText

fun hasText(
    text: String,
    ignoreCase: Boolean = false
): SemanticsPredicate

Returns whether the component's label matches exactly to the given text.

Parameters
text: String Text to match.
ignoreCase: Boolean = false Whether case should be ignored.

hasValue

fun hasValue(value: String): SemanticsPredicate

Returns whether the component's value matches exactly to the given accessibility value.

Parameters
value: String Value to match.

isHidden

fun isHidden(): SemanticsPredicate

Returns whether the component is hidden.

This checks only the property of the component itself. Ignoring parents visibility.

isInMutuallyExclusiveGroup

fun isInMutuallyExclusiveGroup(): SemanticsPredicate

Verifies that the component is in a mutually exclusive group - that is, that FoundationSemanticsProperties.InMutuallyExclusiveGroup is set to true

isNotHidden

fun isNotHidden(): SemanticsPredicate

Returns whether the component is not hidden.

This checks only the property of the component itself. Ignoring parents visibility.

isOff

fun isOff(): SemanticsPredicate

Returns whether the component is not toggled.

isOn

fun isOn(): SemanticsPredicate

Returns whether the component is toggled.

isSelectable

fun isSelectable(): SemanticsPredicate

Return whether the component is selectable.

isSelected

fun isSelected(): SemanticsPredicate

Returns whether the component is selected.

isToggleable

fun isToggleable(): SemanticsPredicate

Return whether the component is checkable.

isUnselected

fun isUnselected(): SemanticsPredicate

Returns whether the component is not selected.

Top-level properties

BigTestConstraints

val BigTestConstraints: DpConstraints

Constant to emulate very big but finite constraints

Extension functions

assert

fun SemanticsNodeInteraction.assert(predicate: SemanticsPredicate): SemanticsNodeInteraction

Asserts that the provided predicate is satisfied for this node.

Parameters
predicate: SemanticsPredicate Predicate to verify.
Exceptions
AssertionError if the predicate fails or the node can no longer be found.

assertEquals

fun SemanticsConfiguration.assertEquals(expected: SemanticsConfiguration): Unit

assertHasClickAction

fun SemanticsNodeInteraction.assertHasClickAction(): SemanticsNodeInteraction

Asserts that the current component has a click action.

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

assertHasNoClickAction

fun SemanticsNodeInteraction.assertHasNoClickAction(): SemanticsNodeInteraction

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

Throws AssertionError if the component has a click action.

assertHasPendingChanges

fun ComposeExecutionControl.assertHasPendingChanges(): Unit

Performs recomposition and asserts that there were some pending changes.

Exceptions
AssertionError if recomposition has no pending changes.

assertIsDisplayed

fun SemanticsNodeInteraction.assertIsDisplayed(): SemanticsNodeInteraction

Asserts that the current component is displayed on screen.

Throws AssertionError if the component is not displayed.

assertIsHidden

fun SemanticsNodeInteraction.assertIsHidden(): SemanticsNodeInteraction

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

Note that this does not verify parents of the component. For stronger guarantees of visibility see assertIsNotDisplayed. If you want to assert that the component is not even in the hierarchy use SemanticsNodeInteraction.assertDoesNotExist.

Throws AssertionError if the component is not hidden.

assertIsInMutuallyExclusiveGroup

fun SemanticsNodeInteraction.assertIsInMutuallyExclusiveGroup(): SemanticsNodeInteraction

Asserts the component is in a mutually exclusive group. This is used by radio groups to assert only one is selected at a given time.

assertIsNotDisplayed

fun SemanticsNodeInteraction.assertIsNotDisplayed(): SemanticsNodeInteraction

Asserts that the current component is not displayed on screen.

Throws AssertionError if the component is displayed.

assertIsNotHidden

fun SemanticsNodeInteraction.assertIsNotHidden(): SemanticsNodeInteraction

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

Note that this does not verify parents of the component. For stronger guarantees of visibility see assertIsDisplayed. If you only want to assert that the component is in the hierarchy use SemanticsNodeInteraction.assertExists

Throws AssertionError if the component is hidden.

assertIsOff

fun SemanticsNodeInteraction.assertIsOff(): SemanticsNodeInteraction

Asserts that the current component is unchecked.

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

assertIsOn

fun SemanticsNodeInteraction.assertIsOn(): SemanticsNodeInteraction

Asserts that the current component is checked.

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

assertIsSelectable

fun SemanticsNodeInteraction.assertIsSelectable(): SemanticsNodeInteraction

Asserts that the current component is selectable.

Throws AssertionError if the component is not selectable.

assertIsSelected

fun SemanticsNodeInteraction.assertIsSelected(): SemanticsNodeInteraction

Asserts that the current component is selected.

Throws AssertionError if the component is unselected or not selectable.

assertIsToggleable

fun SemanticsNodeInteraction.assertIsToggleable(): SemanticsNodeInteraction

Asserts that the current component is toggleable.

Throws AssertionError if the component is not toggleable.

assertIsUnselected

fun SemanticsNodeInteraction.assertIsUnselected(): SemanticsNodeInteraction

Asserts that the current component is unselected.

Throws AssertionError if the component is selected or not selectable.

assertLabelEquals

fun SemanticsNodeInteraction.assertLabelEquals(value: String): SemanticsNodeInteraction

Asserts the component's label equals the given String. For further details please check SemanticsProperties.AccessibilityLabel. Throws AssertionError if the node's value is not equal to value, or if the node has no value

assertLastRecomposeHadChanges

fun ComposeExecutionControl.assertLastRecomposeHadChanges(): Unit

Asserts that last recomposition had some changes.

assertLastRecomposeHadNoChanges

fun ComposeExecutionControl.assertLastRecomposeHadNoChanges(): Unit

Asserts that last recomposition had no some changes.

assertMeasureSizeIsPositive

fun ComposeExecutionControl.assertMeasureSizeIsPositive(): Unit

Assert that the underlying view under test has a positive size.

Useful to assert that the test case has some content.

Exceptions
AssertionError if the underlying view has zero measured size.

assertNoPendingChanges

fun ComposeExecutionControl.assertNoPendingChanges(): Unit

Performs recomposition and asserts that there were some pending changes.

Exceptions
AssertionError if recomposition has pending changes.

assertPixelColor

fun Bitmap.assertPixelColor(
    expected: Color,
    x: Int,
    y: Int,
    error: (Color) -> String = { color -> "Pixel($x, $y) expected to be $expected, but was $color" }
): Unit

Asserts that the color at a specific pixel in the bitmap at (x, y) is expected.

assertPixels

fun Bitmap.assertPixels(
    expectedSize: IntPxSize? = null,
    expectedColorProvider: (pos: IntPxPosition) -> Color?
): Unit

A helper function to run asserts on Bitmap.

Parameters
expectedSize: IntPxSize? = null The expected size of the bitmap. Leave null to skip the check.
expectedColorProvider: (pos: IntPxPosition) -> Color? Returns the expected color for the provided pixel position. The returned color is then asserted as the expected one on the given bitmap.
Exceptions
AssertionError if size or colors don't match.

assertSemanticsIsEqualTo

fun SemanticsNodeInteraction.assertSemanticsIsEqualTo(expectedProperties: SemanticsConfiguration): SemanticsNodeInteraction

Asserts that the semantics of the component are the same as the given semantics. For further details please check SemanticsConfiguration.assertEquals.

assertShape

fun Bitmap.assertShape(
    density: Density,
    shape: Shape,
    shapeColor: Color,
    backgroundColor: Color,
    backgroundShape: Shape = RectangleShape,
    sizeX: Px = width.toFloat().px,
    sizeY: Px = height.toFloat().px,
    shapeSizeX: Px = sizeX,
    shapeSizeY: Px = sizeY,
    centerX: Px = width.px / 2f,
    centerY: Px = height.px / 2f,
    shapeOverlapPixelCount: Px = 1.px
): Unit

Asserts that the given shape is drawn within the bitmap with the size the dimensions shapeSizeX x shapeSizeY, centered at (centerX, centerY) with the color shapeColor. The bitmap area examined is sizeX x sizeY, centered at (centerX, centerY) and everything outside the shape is expected to be color backgroundColor.

The border area of 1 pixel from the shape outline is left untested as it is likely anti-aliased.

assertValueEquals

fun SemanticsNodeInteraction.assertValueEquals(value: String): SemanticsNodeInteraction

Asserts the component's value equals the given value.

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

callSemanticsAction

fun <T : Function<Unit>> SemanticsNodeInteraction.callSemanticsAction(
    key: SemanticsPropertyKey<AccessibilityAction<T>>,
    invocation: (T) -> Unit
): Unit

Provides support to call custom semantics actions on this node.

This method is supposed to be used for actions with parameters.

This will properly verify that the actions exists and provide clear error message in case it does not. It also handle synchronization and performing the action on the UI thread. This call is blocking until the action is performed

Parameters
key: SemanticsPropertyKey<AccessibilityAction<T>> Key of the action to be performed.
invocation: (T) -> Unit Place where you call your action. In the argument is provided the underlying action from the given Semantics action.
Exceptions
AssertionError If the semantics action is not defined on this node.

callSemanticsAction

fun SemanticsNodeInteraction.callSemanticsAction(key: SemanticsPropertyKey<AccessibilityAction<() -> Unit>>): Unit

Provides support to call custom semantics actions on this node.

This method is for calling actions that have no parameters.

This will properly verify that the actions exists and provide clear error message in case it does not. It also handle synchronization and performing the action on the UI thread. This call is blocking until the action is performed

Parameters
key: SemanticsPropertyKey<AccessibilityAction<() -> Unit>> Key of the action to be performed.
Exceptions
AssertionError If the semantics action is not defined on this node.

captureToBitmap

fun View.captureToBitmap(): Bitmap

Captures the underlying view's surface into bitmap.

This has currently several limitations. Currently we assume that the view is hosted in Activity's window. Also if there is another window covering part of the component if won't occur in the bitmap as this is taken from the component's window surface.

captureToBitmap

fun SemanticsNodeInteraction.captureToBitmap(): Bitmap

Captures the underlying component's surface into bitmap.

This has currently several limitations. Currently we assume that the component is hosted in Activity's window. Also if there is another window covering part of the component if won't occur in the bitmap as this is taken from the component's window surface.

copyWith

fun SemanticsConfiguration.copyWith(diff: SemanticsConfiguration.() -> Unit): SemanticsConfiguration

Returns a (mutated) copy of the original SemanticsConfiguration object. Uses SemanticsPropertiesBuilder as an intermediate (mutable) representation of SemanticsConfiguration

doClick

fun SemanticsNodeInteraction.doClick(): SemanticsNodeInteraction

Performs a click action on the given component.

doFramesAssertAllHadChangesExceptLastOne

fun ComposeExecutionControl.doFramesAssertAllHadChangesExceptLastOne(numberOfFramesToBeStable: Int): Unit

Performs the given amount of frames and asserts that there are no changes pending afterwards. Also asserts that all the frames (except the last one) had changes to recompose.

Exceptions
AssertionError if any frame before numberOfFramesToBeStable frame had no pending changes or the last frame had pending changes.

doFramesUntilNoChangesPending

fun ComposeExecutionControl.doFramesUntilNoChangesPending(maxAmountOfFrames: Int = 10): Int

Runs frames until there are no changes pending.

Parameters
maxAmountOfFrames: Int = 10 Max amount of frames to perform before giving up and throwing exception.
Exceptions
AssertionError if there are still pending changes after maxAmountOfFrames executed.

doGesture

fun SemanticsNodeInteraction.doGesture(block: GestureScope.() -> Unit): SemanticsNodeInteraction

Executes the gestures specified in the given block.

Example usage: findByTag("myWidget") .doGesture { sendSwipeUp() }

doScrollTo

fun SemanticsNodeInteraction.doScrollTo(): SemanticsNodeInteraction

Scrolls to a component using SemanticsActions. It first identifies a parent component with a Semantics ScrollTo action, then it retrieves the location of the current element and computes the relative coordinates that will be used by the scroller.

Throws AssertionError if there is no parent component with ScrollTo SemanticsAction, the current semantics component doesn't have a bounding rectangle set or if a layout node used to compute the relative coordinates to be fed to the ScrollTo action can't be found.

dumpToString

fun Collection<SemanticsNodeInteraction>.dumpToString(): String

Dumps all the semantics nodes information it holds into string.

Note that this will fetch the latest snapshot of nodes it sees in the hierarchy for the IDs it collected before. So the output can change over time if the tree changes.

dumpToString

fun SemanticsNodeInteraction.dumpToString(): String

Dumps all the semantics nodes information it holds into string.

Note that this will fetch the latest snapshot of nodes it sees in the hierarchy for the IDs it collected before. So the output can change over time if the tree changes.

localToGlobal

fun GestureScope.localToGlobal(position: PxPosition): PxPosition

Transforms the position to global coordinates, as defined by globalBounds

Parameters
position: PxPosition A position in local coordinates

recomposeAssertHadChanges

fun ComposeExecutionControl.recomposeAssertHadChanges(): Unit

Performs recomposition and asserts that there were some pending changes.

Exceptions
AssertionError if last recomposition had no changes.

sendClick

fun GestureScope.sendClick(position: PxPosition): Unit

Performs a click gesture on the given position on the associated component. The position is in the component's local coordinate system, where (0.px, 0.px) is the top left corner of the component.

Throws AssertionError when the component doesn't have a bounding rectangle set

Parameters
position: PxPosition The position where to click, in the component's local coordinate system

sendClick

fun GestureScope.sendClick(): Unit

Performs a click gesture on the associated component. The click is done in the middle of the component's bounds.

Throws AssertionError when the component doesn't have a bounding rectangle set

sendDoubleClick

fun GestureScope.sendDoubleClick(position: PxPosition): Unit

Performs a double click gesture on the given position on the associated component. The position is in the component's local coordinate system, where (0.px, 0.px) is the top left corner of the component.

Throws AssertionError when the component doesn't have a bounding rectangle set

Parameters
position: PxPosition The position of the double click, in the component's local coordinate system

sendDoubleClick

fun GestureScope.sendDoubleClick(): Unit

Performs a double click gesture on the associated component. The clicks are done in the middle of the component's bounds.

Throws AssertionError when the component doesn't have a bounding rectangle set

sendLongClick

fun GestureScope.sendLongClick(position: PxPosition): Unit

Performs a long click gesture on the given position on the associated component. There will be LongPressTimeout + 100 milliseconds time between the down and the up event. The position is in the component's local coordinate system, where (0.px, 0.px) is the top left corner of the component.

Throws AssertionError when the component doesn't have a bounding rectangle set

Parameters
position: PxPosition The position of the long click, in the component's local coordinate system

sendLongClick

fun GestureScope.sendLongClick(): Unit

Performs a long click gesture on the middle of the associated component. There will be LongPressTimeout + 100 milliseconds time between the down and the up event.

Throws AssertionError when the component doesn't have a bounding rectangle set

sendSwipe

fun GestureScope.sendSwipe(
    start: PxPosition,
    end: PxPosition,
    duration: Duration = 200.milliseconds
): Unit

Performs the swipe gesture on the associated component. The motion events are linearly interpolated between start and end. The coordinates are in the component's local coordinate system, where (0.px, 0.px) is the top left corner of the component. The default duration is 200 milliseconds.

Throws AssertionError when the component doesn't have a bounding rectangle set

Parameters
start: PxPosition The start position of the gesture, in the component's local coordinate system
end: PxPosition The end position of the gesture, in the component's local coordinate system
duration: Duration = 200.milliseconds The duration of the gesture

sendSwipeDown

fun GestureScope.sendSwipeDown(): Unit

Performs a swipe down gesture on the associated component. The gesture starts slightly below the top of the component and ends at the bottom.

Throws AssertionError when the component doesn't have a bounding rectangle set

sendSwipeLeft

fun GestureScope.sendSwipeLeft(): Unit

Performs a swipe left gesture on the associated component. The gesture starts slightly left of the right side of the component and ends at the left side.

Throws AssertionError when the component doesn't have a bounding rectangle set

sendSwipeRight

fun GestureScope.sendSwipeRight(): Unit

Performs a swipe right gesture on the associated component. The gesture starts slightly right of the left side of the component and ends at the right side.

Throws AssertionError when the component doesn't have a bounding rectangle set

sendSwipeUp

fun GestureScope.sendSwipeUp(): Unit

Performs a swipe up gesture on the associated component. The gesture starts slightly above the bottom of the component and ends at the top.

Throws AssertionError when the component doesn't have a bounding rectangle set

sendSwipeWithVelocity

fun GestureScope.sendSwipeWithVelocity(
    start: PxPosition,
    end: PxPosition,
    endVelocity: Float,
    duration: Duration = 200.milliseconds
): Unit

Performs the swipe gesture on the associated component, such that the velocity when the gesture is finished is roughly equal to endVelocity. The MotionEvents are linearly interpolated between start and end. The coordinates are in the component's local coordinate system, where (0.px, 0.px) is the top left corner of the component. The default duration is 200 milliseconds.

Note that due to imprecisions, no guarantees can be made on the precision of the actual velocity at the end of the gesture, but generally it is within 0.1% of the desired velocity.

Throws AssertionError when the component doesn't have a bounding rectangle set

Parameters
start: PxPosition The start position of the gesture, in the component's local coordinate system
end: PxPosition The end position of the gesture, in the component's local coordinate system
endVelocity: Float The velocity of the gesture at the moment it ends. Must be positive.
duration: Duration = 200.milliseconds The duration of the gesture. Must be long enough that at least 3 input events are generated, which happens with a duration of 25ms or more.

setContentAndCollectSizes

fun ComposeTestRule.setContentAndCollectSizes(
    parentConstraints: DpConstraints = BigTestConstraints,
    children: () -> Unit
): CollectedSizes

Set content as with ComposeTestRule.setContent, but return CollectedSizes to assert width and height of this content

Parameters
parentConstraints: DpConstraints = BigTestConstraints desired parent constraints for content
children: () -> Unit content to set

setContentAndGetPixelSize

fun ComposeTestRule.setContentAndGetPixelSize(
    parentConstraints: DpConstraints = BigTestConstraints,
    performSetContent: (() -> Unit) -> Unit = { setContent(it) },
    children: () -> Unit
): PxSize

Set content as with ComposeTestRule.setContent, but return sizes of this content

Parameters
parentConstraints: DpConstraints = BigTestConstraints desired parent constraints for content
performSetContent: (() -> Unit) -> Unit = { setContent(it) } lambda that should be performed to set content. Defaults to ComposeTestRule.setContent and usually don't need to be changed
children: () -> Unit content to set

setupContent

fun <T> ComposeBenchmarkScope<T>.setupContent(): Unit

Sets up the content. This is by default called by first invocation of ComposeBenchmarkScope.doFrame.

If you want to call this multiple times, make sure you call ComposeBenchmarkScope.disposeContent in between.

Extension properties

center

val GestureScope.center: PxPosition

Returns the center of the component we're interacting with, in the component's local coordinate system, where (0.px, 0.px) is the top left corner of the component.

globalBounds

val GestureScope.globalBounds: PxBounds

Returns the global bounds of the component we're interacting with

positionInParent

val LayoutCoordinates.positionInParent: PxPosition

Returns the position relative to the parent Layout

size

val GestureScope.size: IntPxSize

Returns the size of the component we're interacting with