UiScrollable


class UiScrollable : UiCollection


UiScrollable is a UiCollection and provides support for searching for items in scrollable layout elements. This class can be used with horizontally or vertically scrollable controls.

Summary

Public constructors

Constructor.

Public functions

Boolean

Performs a backwards fling action with the default number of fling steps (5).

Boolean

Performs a forward fling with the default number of fling steps (5).

Boolean
flingToBeginning(maxSwipes: Int)

Performs a fling gesture to reach the beginning of a scrollable layout element.

Boolean
flingToEnd(maxSwipes: Int)

Performs a fling gesture to reach the end of a scrollable layout element.

UiObject
getChildByDescription(childPattern: UiSelector, text: String)

Searches for a child element in the present scrollable container.

UiObject
getChildByDescription(
    childPattern: UiSelector,
    text: String,
    allowScrollSearch: Boolean
)

Searches for a child element in the present scrollable container.

UiObject
getChildByInstance(childPattern: UiSelector, instance: Int)

Searches for a child element in the present scrollable container that matches the selector you provided.

UiObject
getChildByText(childPattern: UiSelector, text: String)

Searches for a child element in the present scrollable container.

UiObject
getChildByText(
    childPattern: UiSelector,
    text: String,
    allowScrollSearch: Boolean
)

Searches for a child element in the present scrollable container.

Int

Gets the maximum number of scrolls allowed when performing a scroll action in search of a child element.

Double

Returns the percentage of a widget's size that's considered as a no-touch zone when swiping.

Boolean

Performs a backward scroll with the default number of scroll steps (55).

Boolean

Performs a backward scroll.

Boolean

Performs a forward scroll action on the scrollable layout element until the content-description is found, or until swipe attempts have been exhausted.

Boolean

Performs a forward scroll with the default number of scroll steps (55).

Boolean

Performs a forward scroll.

Boolean

Perform a forward scroll action to move through the scrollable layout element until a visible item that matches the UiObject is found.

Boolean

Perform a scroll forward action to move through the scrollable layout element until a visible item that matches the selector is found.

Boolean

Performs a forward scroll action on the scrollable layout element until the text you provided is visible, or until swipe attempts have been exhausted.

Boolean
scrollToBeginning(maxSwipes: Int)

Scrolls to the beginning of a scrollable layout element.

Boolean
scrollToBeginning(maxSwipes: Int, steps: Int)

Scrolls to the beginning of a scrollable layout element.

Boolean
scrollToEnd(maxSwipes: Int)

Scrolls to the end of a scrollable layout element.

Boolean
scrollToEnd(maxSwipes: Int, steps: Int)

Scrolls to the end of a scrollable layout element.

UiScrollable

Set the direction of swipes to be horizontal when performing scroll actions.

UiScrollable

Set the direction of swipes to be vertical when performing scroll actions.

UiScrollable

Sets the maximum number of scrolls allowed when performing a scroll action in search of a child element.

UiScrollable
setSwipeDeadZonePercentage(swipeDeadZonePercentage: Double)

Sets the percentage of a widget's size that's considered as no-touch zone when swiping.

Protected functions

Boolean
exists(selector: UiSelector)

Used privately when performing swipe searches to decide if an element has become visible or not.

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.UiCollection
Int
getChildCount(childPattern: UiSelector)

Counts child UI element instances matching the childPattern argument.

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

UiScrollable

Added in 2.2.0
UiScrollable(container: UiSelector)

Constructor.

Parameters
container: UiSelector

a UiSelector selector to identify the scrollable layout element.

Public functions

flingBackward

Added in 2.2.0
fun flingBackward(): Boolean

Performs a backwards fling action with the default number of fling steps (5). If the swipe direction is set to vertical, then the swipe will be performed from top to bottom. If the swipe direction is set to horizontal, then the swipes will be performed from left to right. Make sure to take into account devices configured with right-to-left languages like Arabic and Hebrew.

Returns
Boolean

true if scrolled, and false if can't scroll anymore

flingForward

Added in 2.2.0
fun flingForward(): Boolean

Performs a forward fling with the default number of fling steps (5). If the swipe direction is set to vertical, then the swipes will be performed from bottom to top. If the swipe direction is set to horizontal, then the swipes will be performed from right to left. Make sure to take into account devices configured with right-to-left languages like Arabic and Hebrew.

Returns
Boolean

true if scrolled, false if can't scroll anymore

flingToBeginning

Added in 2.2.0
fun flingToBeginning(maxSwipes: Int): Boolean

Performs a fling gesture to reach the beginning of a scrollable layout element. The beginning can be at the top-most edge in the case of vertical controls, or the left-most edge for horizontal controls. Make sure to take into account devices configured with right-to-left languages like Arabic and Hebrew.

Parameters
maxSwipes: Int

maximum number of flings allowed

Returns
Boolean

true if beginning reached within maxSwipes

flingToEnd

Added in 2.2.0
fun flingToEnd(maxSwipes: Int): Boolean

Performs a fling gesture to reach the end of a scrollable layout element. The end can be at the bottom-most edge in the case of vertical controls, or the right-most edge for horizontal controls. Make sure to take into account devices configured with right-to-left languages like Arabic and Hebrew.

Parameters
maxSwipes: Int

maximum number of flings allowed

Returns
Boolean

true if end reached within maxSwipes

getChildByDescription

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

Searches for a child element in the present scrollable container. The search first looks for a child element that matches the selector you provided, then looks for the content-description in its children elements. If both search conditions are fulfilled, the method returns a UiObject representing the element matching the selector (not the child element in its subhierarchy containing the content-description). By default, this method performs a scroll search. See getChildByDescription

Parameters
childPattern: UiSelector

UiSelector for a child in a scollable layout element

text: String

Content-description to find in the children of the childPattern match

Returns
UiObject

UiObject representing the child element that matches the search conditions

getChildByDescription

Added in 2.2.0
fun getChildByDescription(
    childPattern: UiSelector,
    text: String,
    allowScrollSearch: Boolean
): UiObject

Searches for a child element in the present scrollable container. The search first looks for a child element that matches the selector you provided, then looks for the content-description in its children elements. If both search conditions are fulfilled, the method returns a UiObject representing the element matching the selector (not the child element in its subhierarchy containing the content-description).

Parameters
childPattern: UiSelector

UiSelector for a child in a scollable layout element

text: String

Content-description to find in the children of the childPattern match (may be a partial match)

allowScrollSearch: Boolean

set to true if scrolling is allowed

Returns
UiObject

UiObject representing the child element that matches the search conditions

getChildByInstance

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

Searches for a child element in the present scrollable container that matches the selector you provided. The search is performed without scrolling and only on visible elements.

Parameters
childPattern: UiSelector

UiSelector for a child in a scollable layout element

instance: Int

int number representing the occurance of a childPattern match

Returns
UiObject

UiObject representing the child element that matches the search conditions

getChildByText

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

Searches for a child element in the present scrollable container. The search first looks for a child element that matches the selector you provided, then looks for the text in its children elements. If both search conditions are fulfilled, the method returns a UiObject representing the element matching the selector (not the child element in its subhierarchy containing the text). By default, this method performs a scroll search. See getChildByText

Parameters
childPattern: UiSelector

UiSelector selector for a child in a scrollable layout element

text: String

String to find in the children of the childPattern match

Returns
UiObject

UiObject representing the child element that matches the search conditions

getChildByText

Added in 2.2.0
fun getChildByText(
    childPattern: UiSelector,
    text: String,
    allowScrollSearch: Boolean
): UiObject

Searches for a child element in the present scrollable container. The search first looks for a child element that matches the selector you provided, then looks for the text in its children elements. If both search conditions are fulfilled, the method returns a UiObject representing the element matching the selector (not the child element in its subhierarchy containing the text).

Parameters
childPattern: UiSelector

UiSelector selector for a child in a scrollable layout element

text: String

String to find in the children of the childPattern match

allowScrollSearch: Boolean

set to true if scrolling is allowed

Returns
UiObject

UiObject representing the child element that matches the search conditions

getMaxSearchSwipes

Added in 2.2.0
fun getMaxSearchSwipes(): Int

Gets the maximum number of scrolls allowed when performing a scroll action in search of a child element. See getChildByDescription and getChildByText.

Returns
Int

max the number of search swipes to perform until giving up

getSwipeDeadZonePercentage

Added in 2.2.0
fun getSwipeDeadZonePercentage(): Double

Returns the percentage of a widget's size that's considered as a no-touch zone when swiping. The no-touch zone is set as a percentage of a widget's total width or height, denoting a margin around the swipable area of the widget. Swipes must start and end inside this margin. This is important when the widget being swiped may not respond to the swipe if started at a point too near to the edge. The default is 10% from either edge.

Returns
Double

a value between 0 and 1

scrollBackward

Added in 2.2.0
fun scrollBackward(): Boolean

Performs a backward scroll with the default number of scroll steps (55). If the swipe direction is set to vertical, then the swipes will be performed from top to bottom. If the swipe direction is set to horizontal, then the swipes will be performed from left to right. Make sure to take into account devices configured with right-to-left languages like Arabic and Hebrew.

Returns
Boolean

true if scrolled, and false if can't scroll anymore

scrollBackward

Added in 2.2.0
fun scrollBackward(steps: Int): Boolean

Performs a backward scroll. If the swipe direction is set to vertical, then the swipes will be performed from top to bottom. If the swipe direction is set to horizontal, then the swipes will be performed from left to right. Make sure to take into account devices configured with right-to-left languages like Arabic and Hebrew.

Parameters
steps: Int

number of steps. Use this to control the speed of the scroll action.

Returns
Boolean

true if scrolled, false if can't scroll anymore

scrollDescriptionIntoView

Added in 2.2.0
fun scrollDescriptionIntoView(text: String): Boolean

Performs a forward scroll action on the scrollable layout element until the content-description is found, or until swipe attempts have been exhausted. See setMaxSearchSwipes

Parameters
text: String

content-description to find within the contents of this scrollable layout element.

Returns
Boolean

true if item is found; else, false

scrollForward

Added in 2.2.0
fun scrollForward(): Boolean

Performs a forward scroll with the default number of scroll steps (55). If the swipe direction is set to vertical, then the swipes will be performed from bottom to top. If the swipe direction is set to horizontal, then the swipes will be performed from right to left. Make sure to take into account devices configured with right-to-left languages like Arabic and Hebrew.

Returns
Boolean

true if scrolled, false if can't scroll anymore

scrollForward

Added in 2.2.0
fun scrollForward(steps: Int): Boolean

Performs a forward scroll. If the swipe direction is set to vertical, then the swipes will be performed from bottom to top. If the swipe direction is set to horizontal, then the swipes will be performed from right to left. Make sure to take into account devices configured with right-to-left languages like Arabic and Hebrew.

Parameters
steps: Int

number of steps. Use this to control the speed of the scroll action

Returns
Boolean

true if scrolled, false if can't scroll anymore

scrollIntoView

Added in 2.2.0
fun scrollIntoView(obj: UiObject): Boolean

Perform a forward scroll action to move through the scrollable layout element until a visible item that matches the UiObject is found.

Parameters
obj: UiObject

UiObject

Returns
Boolean

true if the item was found and now is in view else false

scrollIntoView

Added in 2.2.0
fun scrollIntoView(selector: UiSelector): Boolean

Perform a scroll forward action to move through the scrollable layout element until a visible item that matches the selector is found. See scrollDescriptionIntoView and scrollTextIntoView.

Parameters
selector: UiSelector

UiSelector selector

Returns
Boolean

true if the item was found and now is in view; else, false

scrollTextIntoView

Added in 2.2.0
fun scrollTextIntoView(text: String): Boolean

Performs a forward scroll action on the scrollable layout element until the text you provided is visible, or until swipe attempts have been exhausted. See setMaxSearchSwipes

Parameters
text: String

test to look for

Returns
Boolean

true if item is found; else, false

scrollToBeginning

Added in 2.2.0
fun scrollToBeginning(maxSwipes: Int): Boolean

Scrolls to the beginning of a scrollable layout element. The beginning can be at the top-most edge in the case of vertical controls, or the left-most edge for horizontal controls. Make sure to take into account devices configured with right-to-left languages like Arabic and Hebrew.

Parameters
maxSwipes: Int

maximum number of scrolls allowed

Returns
Boolean

true if beginning reached within maxSwipes

scrollToBeginning

Added in 2.2.0
fun scrollToBeginning(maxSwipes: Int, steps: Int): Boolean

Scrolls to the beginning of a scrollable layout element. The beginning can be at the top-most edge in the case of vertical controls, or the left-most edge for horizontal controls. Make sure to take into account devices configured with right-to-left languages like Arabic and Hebrew.

Parameters
maxSwipes: Int

maximum number of scrolls allowed

steps: Int

use steps to control the speed, so that it may be a scroll, or fling

Returns
Boolean

true if beginning reached within maxSwipes

scrollToEnd

Added in 2.2.0
fun scrollToEnd(maxSwipes: Int): Boolean

Scrolls to the end of a scrollable layout element. The end can be at the bottom-most edge in the case of vertical controls, or the right-most edge for horizontal controls. Make sure to take into account devices configured with right-to-left languages like Arabic and Hebrew.

Parameters
maxSwipes: Int

maximum number of scrolls allowed

Returns
Boolean

true if end reached within maxSwipes

scrollToEnd

Added in 2.2.0
fun scrollToEnd(maxSwipes: Int, steps: Int): Boolean

Scrolls to the end of a scrollable layout element. The end can be at the bottom-most edge in the case of vertical controls, or the right-most edge for horizontal controls. Make sure to take into account devices configured with right-to-left languages like Arabic and Hebrew.

Parameters
maxSwipes: Int

maximum number of scrolls allowed

steps: Int

use steps to control the speed, so that it may be a scroll, or fling

Returns
Boolean

true if end reached within maxSwipes

setAsHorizontalList

Added in 2.2.0
fun setAsHorizontalList(): UiScrollable

Set the direction of swipes to be horizontal when performing scroll actions.

Returns
UiScrollable

reference to itself

setAsVerticalList

Added in 2.2.0
fun setAsVerticalList(): UiScrollable

Set the direction of swipes to be vertical when performing scroll actions.

Returns
UiScrollable

reference to itself

setMaxSearchSwipes

Added in 2.2.0
fun setMaxSearchSwipes(swipes: Int): UiScrollable

Sets the maximum number of scrolls allowed when performing a scroll action in search of a child element. See getChildByDescription and getChildByText.

Parameters
swipes: Int

the number of search swipes to perform until giving up

Returns
UiScrollable

reference to itself

setSwipeDeadZonePercentage

Added in 2.2.0
fun setSwipeDeadZonePercentage(swipeDeadZonePercentage: Double): UiScrollable

Sets the percentage of a widget's size that's considered as no-touch zone when swiping. The no-touch zone is set as percentage of a widget's total width or height, denoting a margin around the swipable area of the widget. Swipes must always start and end inside this margin. This is important when the widget being swiped may not respond to the swipe if started at a point too near to the edge. The default is 10% from either edge.

Parameters
swipeDeadZonePercentage: Double

is a value between 0 and 1

Returns
UiScrollable

reference to itself

Protected functions

exists

Added in 2.2.0
protected fun exists(selector: UiSelector): Boolean

Used privately when performing swipe searches to decide if an element has become visible or not.

Parameters
selector: UiSelector
Returns
Boolean

true if found else false