UiScrollable
class UiScrollable : UiCollection
| kotlin.Any | |||
| ↳ | androidx.test.uiautomator.UiObject | ||
| ↳ | androidx.test.uiautomator.UiCollection | ||
| ↳ | androidx.test.uiautomator.UiScrollable |
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 |
|---|
UiScrollable(container: UiSelector)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(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(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 |
scrollBackward(steps: Int)Performs a backward scroll. |
Boolean |
scrollDescriptionIntoView(text: String)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 |
scrollForward(steps: Int)Performs a forward scroll. |
Boolean |
scrollIntoView(obj: UiObject)Perform a forward scroll action to move through the scrollable layout element until a visible item that matches the |
Boolean |
scrollIntoView(selector: UiSelector)Perform a scroll forward action to move through the scrollable layout element until a visible item that matches the selector is found. |
Boolean |
scrollTextIntoView(text: String)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 |
setMaxSearchSwipes(swipes: Int)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 |
||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
UiScrollable
UiScrollable(container: UiSelector)
Constructor.
| Parameters | |
|---|---|
container: UiSelector |
a |
Public functions
flingBackward
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
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
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
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 |
|
text: String |
Content-description to find in the children of the |
getChildByDescription
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 |
|
text: String |
Content-description to find in the children of the |
allowScrollSearch: Boolean |
set to true if scrolling is allowed |
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 |
|
instance: Int |
int number representing the occurance of a |
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 |
|
text: String |
String to find in the children of the |
getChildByText
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 |
|
text: String |
String to find in the children of the |
allowScrollSearch: Boolean |
set to true if scrolling is allowed |
getMaxSearchSwipes
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
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
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
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
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
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
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
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.
| Returns | |
|---|---|
Boolean |
true if the item was found and now is in view else false |
scrollIntoView
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 |
|
| Returns | |
|---|---|
Boolean |
true if the item was found and now is in view; else, false |
scrollTextIntoView
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
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
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
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
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
fun setAsHorizontalList(): UiScrollable
Set the direction of swipes to be horizontal when performing scroll actions.
| Returns | |
|---|---|
UiScrollable |
reference to itself |
setAsVerticalList
fun setAsVerticalList(): UiScrollable
Set the direction of swipes to be vertical when performing scroll actions.
| Returns | |
|---|---|
UiScrollable |
reference to itself |
setMaxSearchSwipes
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
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
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 |