public class UiCollection extends UiObject

Known direct subclasses
UiScrollable

UiScrollable is a UiCollection and provides support for searching for items in scrollable layout elements.


Used to enumerate a container's UI elements for the purpose of counting, or targeting a sub elements by a child's text or description.

Summary

Public constructors

Constructs an instance as described by the selector

Public methods

@NonNull UiObject
getChildByDescription(
    @NonNull UiSelector childPattern,
    @NonNull String text
)

Searches for child UI element within the constraints of this UiCollection UiSelector selector.

@NonNull UiObject
getChildByInstance(@NonNull UiSelector childPattern, int instance)

Searches for child UI element within the constraints of this UiCollection UiSelector selector.

@NonNull UiObject

Searches for child UI element within the constraints of this UiCollection UiSelector selector.

int

Counts child UI element instances matching the childPattern argument.

Inherited Constants

From androidx.test.uiautomator.UiObject
static final int
static final int
static final long

This field is deprecated.

use setScrollAcknowledgmentTimeout

static final long
static final long

This field is deprecated.

use setWaitForSelectorTimeout

static final long

Inherited methods

From androidx.test.uiautomator.UiObject
void

Clears the existing text contents in an editable field.

boolean

Performs a click at the center of the visible bounds of the UI element represented by this UiObject.

boolean

Waits for window transitions that would typically take longer than the usual default timeouts.

boolean

Performs a click at the center of the visible bounds of the UI element represented by this UiObject and waits for window transitions.

boolean

Clicks the bottom and right corner of the UI element

boolean

Clicks the top and left corner of the UI element

boolean
dragTo(@NonNull UiObject destObj, int steps)

Drags this object to a destination UiObject.

boolean
dragTo(int destX, int destY, int steps)

Drags this object to arbitrary coordinates.

boolean

Check if view exists.

@Nullable AccessibilityNodeInfo

Finds a matching UI element in the accessibility hierarchy, by using the selector for this UiObject.

@NonNull Rect

Returns the view's bounds property.

@NonNull UiObject

Creates a new UiObject for a child view that is under the present UiObject.

int

Counts the child views immediately under the present UiObject.

@NonNull String

Retrieves the className property of the UI element.

@NonNull String

Reads the content_desc property of the UI element

@NonNull UiObject

Creates a new UiObject for a sibling view or a child of the sibling view, relative to the present UiObject.

@NonNull String

Reads the view's package property

final @NonNull UiSelector

Debugging helper.

@NonNull String

Reads the text property of the UI element

@NonNull Rect

Returns the visible bounds of the view.

boolean

Checks if the UI element's checkable property is currently true.

boolean

Check if the UI element's checked property is currently true

boolean

Checks if the UI element's clickable property is currently true.

boolean

Checks if the UI element's enabled property is currently true.

boolean

Check if the UI element's focusable property is currently true.

boolean

Check if the UI element's focused property is currently true

boolean

Check if the view's long-clickable property is currently true

boolean

Check if the view's scrollable property is currently true

boolean

Checks if the UI element's selected property is currently true.

boolean

Long clicks the center of the visible bounds of the UI element

boolean

Long clicks bottom and right corner of the UI element

boolean

Long clicks on the top and left corner of the UI element

boolean
performMultiPointerGesture(
    @NonNull MotionEvent.PointerCoords[][] touches
)

Performs a multi-touch gesture.

boolean
performTwoPointerGesture(
    @NonNull Point startPoint1,
    @NonNull Point startPoint2,
    @NonNull Point endPoint1,
    @NonNull Point endPoint2,
    int steps
)

Generates a two-pointer gesture with arbitrary starting and ending points.

boolean
pinchIn(int percent, int steps)

Performs a two-pointer gesture, where each pointer moves diagonally toward the other, from the edges to the center of this UiObject .

boolean
pinchOut(int percent, int steps)

Performs a two-pointer gesture, where each pointer moves diagonally opposite across the other, from the center out towards the edges of the this UiObject.

boolean

Sets the text in an editable field, after clearing the field's content.

boolean
swipeDown(int steps)

Performs the swipe down action on the UiObject.

boolean
swipeLeft(int steps)

Performs the swipe left action on the UiObject.

boolean
swipeRight(int steps)

Performs the swipe right action on the UiObject.

boolean
swipeUp(int steps)

Performs the swipe up action on the UiObject.

boolean
waitForExists(long timeout)

Waits a specified length of time for a view to become visible.

boolean
waitUntilGone(long timeout)

Waits a specified length of time for a view to become undetectable.

Public constructors

UiCollection

public UiCollection(@NonNull UiSelector selector)

Constructs an instance as described by the selector

Parameters
@NonNull UiSelector selector

Public methods

getChildByDescription

public @NonNull UiObject getChildByDescription(
    @NonNull UiSelector childPattern,
    @NonNull String text
)

Searches for child UI element within the constraints of this UiCollection UiSelector selector. It looks for any child matching the childPattern argument that has a child UI element anywhere within its sub hierarchy that has content-description text. The returned UiObject will point at the childPattern instance that matched the search and not at the identifying child element that matched the content description.

Parameters
@NonNull UiSelector childPattern

UiSelector selector of the child pattern to match and return

@NonNull String text

String of the identifying child contents of of the childPattern

Returns
@NonNull UiObject

UiObject pointing at and instance of childPattern

getChildByInstance

public @NonNull UiObject getChildByInstance(@NonNull UiSelector childPattern, int instance)

Searches for child UI element within the constraints of this UiCollection UiSelector selector. It looks for any child matching the childPattern argument that has a child UI element anywhere within its sub hierarchy that is at the instance specified. The operation is performed only on the visible items and no scrolling is performed in this case.

Parameters
@NonNull UiSelector childPattern

UiSelector selector of the child pattern to match and return

int instance

int the desired matched instance of this childPattern

Returns
@NonNull UiObject

UiObject pointing at and instance of childPattern

getChildByText

public @NonNull UiObject getChildByText(@NonNull UiSelector childPattern, @NonNull String text)

Searches for child UI element within the constraints of this UiCollection UiSelector selector. It looks for any child matching the childPattern argument that has a child UI element anywhere within its sub hierarchy that has text attribute = text. The returned UiObject will point at the childPattern instance that matched the search and not at the identifying child element that matched the text attribute.

Parameters
@NonNull UiSelector childPattern

UiSelector selector of the child pattern to match and return

@NonNull String text

String of the identifying child contents of of the childPattern

Returns
@NonNull UiObject

UiObject pointing at and instance of childPattern

getChildCount

public int getChildCount(@NonNull UiSelector childPattern)

Counts child UI element instances matching the childPattern argument. The method returns the number of matching UI elements that are currently visible. The count does not include items of a scrollable list that are off-screen.

Parameters
@NonNull UiSelector childPattern

a UiSelector that represents the matching child UI elements to count

Returns
int

the number of matched childPattern under the current UiCollection