class UiCollection : 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 functions

UiObject
getChildByDescription(childPattern: UiSelector, text: String)

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

UiObject
getChildByInstance(childPattern: UiSelector, instance: Int)

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

UiObject
getChildByText(childPattern: UiSelector, text: String)

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

Int
getChildCount(childPattern: UiSelector)

Counts child UI element instances matching the childPattern argument.

Inherited Constants

From androidx.test.uiautomator.UiObject
const Int
const Int
const Long

This property is deprecated.

use setScrollAcknowledgmentTimeout

const Long
const Long

This property is deprecated.

use setWaitForSelectorTimeout

const Long

Inherited functions

From androidx.test.uiautomator.UiObject
Unit

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(destObj: UiObject, steps: Int)

Drags this object to a destination UiObject.

Boolean
dragTo(destX: Int, destY: Int, steps: Int)

Drags this object to arbitrary coordinates.

Boolean

Check if view exists.

AccessibilityNodeInfo?

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

Rect

Returns the view's bounds property.

UiObject
getChild(selector: UiSelector)

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

Int

Counts the child views immediately under the present UiObject.

String

Retrieves the className property of the UI element.

String

Reads the content_desc property of the UI element

UiObject

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

String

Reads the view's package property

UiSelector

Debugging helper.

String

Reads the text property of the UI element

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

Performs a multi-touch gesture.

Boolean
performTwoPointerGesture(
    startPoint1: Point,
    startPoint2: Point,
    endPoint1: Point,
    endPoint2: Point,
    steps: Int
)

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

Boolean
pinchIn(percent: Int, steps: Int)

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

Boolean
pinchOut(percent: Int, steps: Int)

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
setText(text: String?)

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

Boolean
swipeDown(steps: Int)

Performs the swipe down action on the UiObject.

Boolean
swipeLeft(steps: Int)

Performs the swipe left action on the UiObject.

Boolean
swipeRight(steps: Int)

Performs the swipe right action on the UiObject.

Boolean
swipeUp(steps: Int)

Performs the swipe up action on the UiObject.

Boolean
waitForExists(timeout: Long)

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

Boolean
waitUntilGone(timeout: Long)

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

Public constructors

UiCollection

UiCollection(selector: UiSelector)

Constructs an instance as described by the selector

Parameters
selector: UiSelector

Public functions

getChildByDescription

fun getChildByDescription(childPattern: UiSelector, text: String): UiObject

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
childPattern: UiSelector

UiSelector selector of the child pattern to match and return

text: String

String of the identifying child contents of of the childPattern

Returns
UiObject

UiObject pointing at and instance of childPattern

getChildByInstance

fun getChildByInstance(childPattern: UiSelector, instance: Int): UiObject

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
childPattern: UiSelector

UiSelector selector of the child pattern to match and return

instance: Int

int the desired matched instance of this childPattern

Returns
UiObject

UiObject pointing at and instance of childPattern

getChildByText

fun getChildByText(childPattern: UiSelector, text: String): UiObject

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
childPattern: UiSelector

UiSelector selector of the child pattern to match and return

text: String

String of the identifying child contents of of the childPattern

Returns
UiObject

UiObject pointing at and instance of childPattern

getChildCount

fun getChildCount(childPattern: UiSelector): Int

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
childPattern: UiSelector

a UiSelector that represents the matching child UI elements to count

Returns
Int

the number of matched childPattern under the current UiCollection