UiScrollable
public class UiScrollable extends UiCollection
java.lang.Object | |||
↳ | 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(@NonNull UiSelector container) Constructor. |
Public methods |
|
---|---|
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(int maxSwipes) Performs a fling gesture to reach the beginning of a scrollable layout element. |
boolean |
flingToEnd(int maxSwipes) Performs a fling gesture to reach the end of a scrollable layout element. |
@NonNull UiObject |
getChildByDescription( Searches for a child element in the present scrollable container. |
@NonNull UiObject |
getChildByDescription( Searches for a child element in the present scrollable container. |
@NonNull UiObject |
getChildByInstance(@NonNull UiSelector childPattern, int instance) Searches for a child element in the present scrollable container that matches the selector you provided. |
@NonNull UiObject |
getChildByText(@NonNull UiSelector childPattern, @NonNull String text) Searches for a child element in the present scrollable container. |
@NonNull 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(int steps) 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 |
scrollForward(int steps) Performs a forward scroll. |
boolean |
scrollIntoView(@NonNull UiObject obj) Perform a forward scroll action to move through the scrollable layout element until a visible item that matches the |
boolean |
scrollIntoView(@NonNull UiSelector selector) Perform a scroll forward action to move through the scrollable layout element until a visible item that matches the selector is found. |
boolean |
scrollTextIntoView(@NonNull String text) 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(int maxSwipes) Scrolls to the beginning of a scrollable layout element. |
boolean |
scrollToBeginning(int maxSwipes, int steps) Scrolls to the beginning of a scrollable layout element. |
boolean |
scrollToEnd(int maxSwipes) Scrolls to the end of a scrollable layout element. |
boolean |
scrollToEnd(int maxSwipes, int steps) Scrolls to the end of a scrollable layout element. |
@NonNull UiScrollable |
Set the direction of swipes to be horizontal when performing scroll actions. |
@NonNull UiScrollable |
Set the direction of swipes to be vertical when performing scroll actions. |
@NonNull UiScrollable |
setMaxSearchSwipes(int swipes) Sets the maximum number of scrolls allowed when performing a scroll action in search of a child element. |
@NonNull UiScrollable |
setSwipeDeadZonePercentage(double swipeDeadZonePercentage) Sets the percentage of a widget's size that's considered as no-touch zone when swiping. |
Protected methods |
|
---|---|
boolean |
exists(@NonNull UiSelector selector) Used privately when performing swipe searches to decide if an element has become visible or not. |
Inherited Constants |
||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
UiScrollable
public UiScrollable(@NonNull UiSelector container)
Constructor.
Parameters | |
---|---|
@NonNull UiSelector container |
a |
Public methods
flingBackward
public boolean flingBackward()
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
public boolean flingForward()
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
public boolean flingToBeginning(int maxSwipes)
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 | |
---|---|
int maxSwipes |
maximum number of flings allowed |
Returns | |
---|---|
boolean |
true if beginning reached within maxSwipes |
flingToEnd
public boolean flingToEnd(int maxSwipes)
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 | |
---|---|
int maxSwipes |
maximum number of flings allowed |
Returns | |
---|---|
boolean |
true if end reached within maxSwipes |
getChildByDescription
public @NonNull UiObject getChildByDescription(
@NonNull UiSelector childPattern,
@NonNull String text
)
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 | |
---|---|
@NonNull UiSelector childPattern |
|
@NonNull String text |
Content-description to find in the children of the |
getChildByDescription
public @NonNull UiObject getChildByDescription(
@NonNull UiSelector childPattern,
@NonNull String text,
boolean allowScrollSearch
)
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 | |
---|---|
@NonNull UiSelector childPattern |
|
@NonNull String text |
Content-description to find in the children of the |
boolean allowScrollSearch |
set to true if scrolling is allowed |
getChildByInstance
public @NonNull UiObject getChildByInstance(@NonNull UiSelector childPattern, int instance)
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 | |
---|---|
@NonNull UiSelector childPattern |
|
int instance |
int number representing the occurance of a |
getChildByText
public @NonNull UiObject getChildByText(@NonNull UiSelector childPattern, @NonNull String text)
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 | |
---|---|
@NonNull UiSelector childPattern |
|
@NonNull String text |
String to find in the children of the |
getChildByText
public @NonNull UiObject getChildByText(
@NonNull UiSelector childPattern,
@NonNull String text,
boolean allowScrollSearch
)
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 | |
---|---|
@NonNull UiSelector childPattern |
|
@NonNull String text |
String to find in the children of the |
boolean allowScrollSearch |
set to true if scrolling is allowed |
getMaxSearchSwipes
public int getMaxSearchSwipes()
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
public double getSwipeDeadZonePercentage()
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
public boolean scrollBackward()
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
public boolean scrollBackward(int steps)
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 | |
---|---|
int steps |
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
public boolean scrollDescriptionIntoView(@NonNull String text)
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 | |
---|---|
@NonNull String text |
content-description to find within the contents of this scrollable layout element. |
Returns | |
---|---|
boolean |
true if item is found; else, false |
scrollForward
public boolean scrollForward()
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
public boolean scrollForward(int steps)
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 | |
---|---|
int steps |
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
public boolean scrollIntoView(@NonNull UiObject obj)
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
public boolean scrollIntoView(@NonNull UiSelector selector)
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 | |
---|---|
@NonNull UiSelector selector |
|
Returns | |
---|---|
boolean |
true if the item was found and now is in view; else, false |
scrollTextIntoView
public boolean scrollTextIntoView(@NonNull String text)
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
Returns | |
---|---|
boolean |
true if item is found; else, false |
scrollToBeginning
public boolean scrollToBeginning(int maxSwipes)
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 | |
---|---|
int maxSwipes |
maximum number of scrolls allowed |
Returns | |
---|---|
boolean |
true if beginning reached within maxSwipes |
scrollToBeginning
public boolean scrollToBeginning(int maxSwipes, int steps)
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 | |
---|---|
int maxSwipes |
maximum number of scrolls allowed |
int steps |
use steps to control the speed, so that it may be a scroll, or fling |
Returns | |
---|---|
boolean |
true if beginning reached within maxSwipes |
scrollToEnd
public boolean scrollToEnd(int maxSwipes)
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 | |
---|---|
int maxSwipes |
maximum number of scrolls allowed |
Returns | |
---|---|
boolean |
true if end reached within maxSwipes |
scrollToEnd
public boolean scrollToEnd(int maxSwipes, int steps)
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 | |
---|---|
int maxSwipes |
maximum number of scrolls allowed |
int steps |
use steps to control the speed, so that it may be a scroll, or fling |
Returns | |
---|---|
boolean |
true if end reached within maxSwipes |
setAsHorizontalList
public @NonNull UiScrollable setAsHorizontalList()
Set the direction of swipes to be horizontal when performing scroll actions.
Returns | |
---|---|
@NonNull UiScrollable |
reference to itself |
setAsVerticalList
public @NonNull UiScrollable setAsVerticalList()
Set the direction of swipes to be vertical when performing scroll actions.
Returns | |
---|---|
@NonNull UiScrollable |
reference to itself |
setMaxSearchSwipes
public @NonNull UiScrollable setMaxSearchSwipes(int swipes)
Sets the maximum number of scrolls allowed when performing a scroll action in search of a child element. See getChildByDescription
and getChildByText
.
Parameters | |
---|---|
int swipes |
the number of search swipes to perform until giving up |
Returns | |
---|---|
@NonNull UiScrollable |
reference to itself |
setSwipeDeadZonePercentage
public @NonNull UiScrollable setSwipeDeadZonePercentage(double swipeDeadZonePercentage)
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 | |
---|---|
double swipeDeadZonePercentage |
is a value between 0 and 1 |
Returns | |
---|---|
@NonNull UiScrollable |
reference to itself |
Protected methods
exists
protected boolean exists(@NonNull UiSelector selector)
Used privately when performing swipe searches to decide if an element has become visible or not.
Parameters | |
---|---|
@NonNull UiSelector selector |
Returns | |
---|---|
boolean |
true if found else false |