UiScrollable
public
class
UiScrollable
extends 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 methods |
boolean
|
flingBackward()
Performs a backwards fling action with the default number of fling
steps (5).
|
boolean
|
flingForward()
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.
|
UiObject
|
getChildByDescription(UiSelector childPattern, String text)
Searches for a child element in the present scrollable container.
|
UiObject
|
getChildByDescription(UiSelector childPattern, String text, boolean allowScrollSearch)
Searches for a child element in the present scrollable container.
|
UiObject
|
getChildByInstance(UiSelector childPattern, int instance)
Searches for a child element in the present scrollable container that
matches the selector you provided.
|
UiObject
|
getChildByText(UiSelector childPattern, String text, boolean allowScrollSearch)
Searches for a child element in the present scrollable container.
|
UiObject
|
getChildByText(UiSelector childPattern, String text)
Searches for a child element in the present scrollable
container.
|
int
|
getMaxSearchSwipes()
Gets the maximum number of scrolls allowed when performing a
scroll action in search of a child element.
|
double
|
getSwipeDeadZonePercentage()
Returns the percentage of a widget's size that's considered as a no-touch
zone when swiping.
|
boolean
|
scrollBackward(int steps)
Performs a backward scroll.
|
boolean
|
scrollBackward()
Performs a backward scroll with the default number of scroll steps (55).
|
boolean
|
scrollDescriptionIntoView(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.
|
boolean
|
scrollForward(int steps)
Performs a forward scroll.
|
boolean
|
scrollForward()
Performs a forward scroll with the default number of scroll steps (55).
|
boolean
|
scrollIntoView(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
|
scrollIntoView(UiObject obj)
Perform a forward scroll action to move through the scrollable layout element until
a visible item that matches the UiObject is found.
|
boolean
|
scrollTextIntoView(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.
|
UiScrollable
|
setAsHorizontalList()
Set the direction of swipes to be horizontal when performing scroll actions.
|
UiScrollable
|
setAsVerticalList()
Set the direction of swipes to be vertical when performing scroll actions.
|
UiScrollable
|
setMaxSearchSwipes(int swipes)
Sets the maximum number of scrolls allowed when performing a
scroll action in search of a child element.
|
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(UiSelector selector)
Used privately when performing swipe searches to decide if an element has become
visible or not.
|
Inherited methods |
From
class
android.support.test.uiautomator.UiCollection
|
From
class
android.support.test.uiautomator.UiObject
void
|
clearTextField()
Clears the existing text contents in an editable field.
|
boolean
|
click()
Performs a click at the center of the visible bounds of the UI element represented
by this UiObject.
|
boolean
|
clickAndWaitForNewWindow()
Waits for window transitions that would typically take longer than the
usual default timeouts.
|
boolean
|
clickAndWaitForNewWindow(long timeout)
Performs a click at the center of the visible bounds of the UI element represented
by this UiObject and waits for window transitions.
|
boolean
|
clickBottomRight()
Clicks the bottom and right corner of the UI element
|
boolean
|
clickTopLeft()
Clicks the top and left corner of the UI element
|
boolean
|
dragTo(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
|
exists()
Check if view exists.
|
AccessibilityNodeInfo
|
findAccessibilityNodeInfo(long timeout)
Finds a matching UI element in the accessibility hierarchy, by
using the selector for this UiObject.
|
Rect
|
getBounds()
Returns the view's bounds property.
|
UiObject
|
getChild(UiSelector selector)
Creates a new UiObject for a child view that is under the present UiObject.
|
int
|
getChildCount()
Counts the child views immediately under the present UiObject.
|
String
|
getClassName()
Retrieves the className property of the UI element.
|
String
|
getContentDescription()
Reads the content_desc property of the UI element
|
UiObject
|
getFromParent(UiSelector selector)
Creates a new UiObject for a sibling view or a child of the sibling view,
relative to the present UiObject.
|
String
|
getPackageName()
Reads the view's package property
|
final
UiSelector
|
getSelector()
Debugging helper.
|
String
|
getText()
Reads the text property of the UI element
|
Rect
|
getVisibleBounds()
Returns the visible bounds of the view.
|
boolean
|
isCheckable()
Checks if the UI element's checkable property is currently true.
|
boolean
|
isChecked()
Check if the UI element's checked property is currently true
|
boolean
|
isClickable()
Checks if the UI element's clickable property is currently true.
|
boolean
|
isEnabled()
Checks if the UI element's enabled property is currently true.
|
boolean
|
isFocusable()
Check if the UI element's focusable property is currently true.
|
boolean
|
isFocused()
Check if the UI element's focused property is currently true
|
boolean
|
isLongClickable()
Check if the view's long-clickable property is currently true
|
boolean
|
isScrollable()
Check if the view's scrollable property is currently true
|
boolean
|
isSelected()
Checks if the UI element's selected property is currently true.
|
boolean
|
longClick()
Long clicks the center of the visible bounds of the UI element
|
boolean
|
longClickBottomRight()
Long clicks bottom and right corner of the UI element
|
boolean
|
longClickTopLeft()
Long clicks on the top and left corner of the UI element
|
boolean
|
performMultiPointerGesture(PointerCoords... touches)
Performs a multi-touch gesture.
|
boolean
|
performTwoPointerGesture(Point startPoint1, Point startPoint2, Point endPoint1, 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
|
setText(String text)
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.
|
|
From
class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public constructors
UiScrollable
UiScrollable (UiSelector container)
Constructor.
Parameters |
container |
UiSelector :
a UiSelector selector to identify the scrollable
layout element. |
Public methods
flingBackward
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
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
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.
Returns |
boolean |
true on scrolled else false |
flingToEnd
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.
Returns |
boolean |
true on scrolled, else false |
getChildByDescription
UiObject getChildByDescription (UiSelector childPattern,
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 {@ link 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(UiSelector, String, boolean)
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
UiObject getChildByDescription (UiSelector childPattern,
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 {@ link 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
UiObject getChildByInstance (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 |
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
UiObject getChildByText (UiSelector childPattern,
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 {@ link 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 |
getChildByText
UiObject getChildByText (UiSelector childPattern,
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 {@ link 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(UiSelector, String, boolean)
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 |
getSwipeDeadZonePercentage
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
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 |
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 |
scrollBackward
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 |
scrollDescriptionIntoView
boolean scrollDescriptionIntoView (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(int)
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
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 |
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 |
scrollForward
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 |
scrollIntoView
boolean scrollIntoView (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 |
scrollTextIntoView
boolean scrollTextIntoView (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(int)
Parameters |
text |
String :
test to look for |
Returns |
boolean |
true if item is found; else, false |
scrollToBeginning
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.
Returns |
boolean |
true on scrolled else false |
scrollToBeginning
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 |
maxSwipes |
int
|
steps |
int :
use steps to control the speed, so that it may be a scroll, or fling |
Returns |
boolean |
true on scrolled else false |
scrollToEnd
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.
Returns |
boolean |
true on scrolled, else false |
scrollToEnd
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 |
maxSwipes |
int
|
steps |
int :
use steps to control the speed, so that it may be a scroll, or fling |
Returns |
boolean |
true on scrolled else false |
setAsHorizontalList
UiScrollable setAsHorizontalList ()
Set the direction of swipes to be horizontal when performing scroll actions.
setAsVerticalList
UiScrollable setAsVerticalList ()
Set the direction of swipes to be vertical when performing scroll actions.
setSwipeDeadZonePercentage
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 |
swipeDeadZonePercentage |
double :
is a value between 0 and 1 |
Protected methods
exists
boolean exists (UiSelector selector)
Used privately when performing swipe searches to decide if an element has become
visible or not.
Returns |
boolean |
true if found else false |