java.lang.Object | |
↳ | android.support.test.uiautomator.UiObject |
Known Direct Subclasses |
Known Indirect Subclasses |
A UiObject is a representation of a view. It is not in any way directly bound to a
view as an object reference. A UiObject contains information to help it
locate a matching view at runtime based on the UiSelector
properties specified in
its constructor. Once you create an instance of a UiObject, it can
be reused for different views that match the selector criteria.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | FINGER_TOUCH_HALF_WIDTH | ||||||||||
int | SWIPE_MARGIN_LIMIT | ||||||||||
long | WAIT_FOR_EVENT_TMEOUT |
This constant is deprecated.
use setScrollAcknowledgmentTimeout(long)
|
|||||||||
long | WAIT_FOR_SELECTOR_POLL | ||||||||||
long | WAIT_FOR_SELECTOR_TIMEOUT |
This constant is deprecated.
use setWaitForSelectorTimeout(long)
|
|||||||||
long | WAIT_FOR_WINDOW_TMEOUT |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This constructor is deprecated.
Use
findObject(UiSelector) instead. This version hides
UiObject's dependency on UiDevice and is prone to misuse.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Clears the existing text contents in an editable field.
| |||||||||||
Performs a click at the center of the visible bounds of the UI element represented
by this UiObject.
| |||||||||||
Performs a click at the center of the visible bounds of the UI element represented
by this UiObject and waits for window transitions.
| |||||||||||
Waits for window transitions that would typically take longer than the
usual default timeouts.
| |||||||||||
Clicks the bottom and right corner of the UI element
| |||||||||||
Clicks the top and left corner of the UI element
| |||||||||||
Drags this object to a destination UiObject.
| |||||||||||
Drags this object to arbitrary coordinates.
| |||||||||||
Check if view exists.
| |||||||||||
Returns the view's
bounds property.
| |||||||||||
Creates a new UiObject for a child view that is under the present UiObject.
| |||||||||||
Counts the child views immediately under the present UiObject.
| |||||||||||
Retrieves the
className property of the UI element.
| |||||||||||
Reads the
content_desc property of the UI element
| |||||||||||
Creates a new UiObject for a sibling view or a child of the sibling view,
relative to the present UiObject.
| |||||||||||
Reads the view's
package property
| |||||||||||
Debugging helper.
| |||||||||||
Reads the
text property of the UI element
| |||||||||||
Returns the visible bounds of the view.
| |||||||||||
Checks if the UI element's
checkable property is currently true.
| |||||||||||
Check if the UI element's
checked property is currently true
| |||||||||||
Checks if the UI element's
clickable property is currently true.
| |||||||||||
Checks if the UI element's
enabled property is currently true.
| |||||||||||
Check if the UI element's
focusable property is currently true.
| |||||||||||
Check if the UI element's
focused property is currently true
| |||||||||||
Check if the view's
long-clickable property is currently true
| |||||||||||
Check if the view's
scrollable property is currently true
| |||||||||||
Checks if the UI element's
selected property is currently true.
| |||||||||||
Long clicks the center of the visible bounds of the UI element
| |||||||||||
Long clicks bottom and right corner of the UI element
| |||||||||||
Long clicks on the top and left corner of the UI element
| |||||||||||
Performs a multi-touch gesture.
| |||||||||||
Generates a two-pointer gesture with arbitrary starting and ending points.
| |||||||||||
Performs a two-pointer gesture, where each pointer moves diagonally
toward the other, from the edges to the center of this UiObject .
| |||||||||||
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.
| |||||||||||
Sets the text in an editable field, after clearing the field's content.
| |||||||||||
Performs the swipe down action on the UiObject.
| |||||||||||
Performs the swipe left action on the UiObject.
| |||||||||||
Performs the swipe right action on the UiObject.
| |||||||||||
Performs the swipe up action on the UiObject.
| |||||||||||
Waits a specified length of time for a view to become visible.
| |||||||||||
Waits a specified length of time for a view to become undetectable.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Finds a matching UI element in the accessibility hierarchy, by
using the selector for this UiObject.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
This constant is deprecated.
use setScrollAcknowledgmentTimeout(long)
This constant is deprecated.
use setWaitForSelectorTimeout(long)
This constructor is deprecated.
Use findObject(UiSelector)
instead. This version hides
UiObject's dependency on UiDevice and is prone to misuse.
Constructs a UiObject to represent a view that matches the specified selector criteria.
Clears the existing text contents in an editable field.
The UiSelector
of this object must reference a UI element that is editable.
When you call this method, the method sets focus on the editable field, selects all of its
existing content, and clears it by sending a DELETE key press
UiObjectNotFoundException | |
UiObjectNotFoundException |
Performs a click at the center of the visible bounds of the UI element represented by this UiObject.
UiObjectNotFoundException | |
UiObjectNotFoundException |
Performs a click at the center of the visible bounds of the UI element represented
by this UiObject and waits for window transitions.
This method differ from click()
only in that this method waits for a
a new window transition as a result of the click. Some examples of a window transition:
timeout | timeout before giving up on waiting for a new window |
---|
UiObjectNotFoundException | |
UiObjectNotFoundException |
Waits for window transitions that would typically take longer than the
usual default timeouts.
See clickAndWaitForNewWindow(long)
UiObjectNotFoundException | |
UiObjectNotFoundException |
Clicks the bottom and right corner of the UI element
UiObjectNotFoundException | |
UiObjectNotFoundException |
Clicks the top and left corner of the UI element
UiObjectNotFoundException | |
UiObjectNotFoundException |
Drags this object to a destination UiObject. The number of steps specified in your input parameter can influence the drag speed, and varying speeds may impact the results. Consider evaluating different speeds when using this method in your tests.
destObj | the destination UiObject. |
---|---|
steps | usually 40 steps. You can increase or decrease the steps to change the speed. |
UiObjectNotFoundException | |
UiObjectNotFoundException |
Drags this object to arbitrary coordinates. The number of steps specified in your input parameter can influence the drag speed, and varying speeds may impact the results. Consider evaluating different speeds when using this method in your tests.
destX | the X-axis coordinate. |
---|---|
destY | the Y-axis coordinate. |
steps | usually 40 steps. You can increase or decrease the steps to change the speed. |
UiObjectNotFoundException | |
UiObjectNotFoundException |
Check if view exists.
This methods performs a waitForExists(long)
with zero timeout. This
basically returns immediately whether the view represented by this UiObject
exists or not. If you need to wait longer for this view, then see
waitForExists(long)
.
Returns the view's bounds
property. See getVisibleBounds()
UiObjectNotFoundException | |
UiObjectNotFoundException |
Creates a new UiObject for a child view that is under the present UiObject.
selector | for child view to match |
---|
UiObjectNotFoundException |
---|
Counts the child views immediately under the present UiObject.
UiObjectNotFoundException | |
UiObjectNotFoundException |
Retrieves the className
property of the UI element.
UiObjectNotFoundException | if no match was found |
---|
Reads the content_desc
property of the UI element
UiObjectNotFoundException | |
UiObjectNotFoundException |
Creates a new UiObject for a sibling view or a child of the sibling view, relative to the present UiObject.
selector | for a sibling view or children of the sibling view |
---|
UiObjectNotFoundException | |
UiObjectNotFoundException |
Reads the view's package
property
UiObjectNotFoundException | |
UiObjectNotFoundException |
Debugging helper. A test can dump the properties of a selector as a string
to its logs if needed. getSelector().toString();
Reads the text
property of the UI element
UiObjectNotFoundException | if no match could be found |
---|
Returns the visible bounds of the view. If a portion of the view is visible, only the bounds of the visible portion are reported.
UiObjectNotFoundException | |
UiObjectNotFoundException |
Checks if the UI element's checkable
property is currently true.
UiObjectNotFoundException | |
UiObjectNotFoundException |
Check if the UI element's checked
property is currently true
UiObjectNotFoundException |
---|
Checks if the UI element's clickable
property is currently true.
UiObjectNotFoundException | |
UiObjectNotFoundException |
Checks if the UI element's enabled
property is currently true.
UiObjectNotFoundException | |
UiObjectNotFoundException |
Check if the UI element's focusable
property is currently true.
UiObjectNotFoundException | |
UiObjectNotFoundException |
Check if the UI element's focused
property is currently true
UiObjectNotFoundException | |
UiObjectNotFoundException |
Check if the view's long-clickable
property is currently true
UiObjectNotFoundException | |
UiObjectNotFoundException |
Check if the view's scrollable
property is currently true
UiObjectNotFoundException | |
UiObjectNotFoundException |
Checks if the UI element's selected
property is currently true.
UiObjectNotFoundException | |
UiObjectNotFoundException |
Long clicks the center of the visible bounds of the UI element
UiObjectNotFoundException | |
UiObjectNotFoundException |
Long clicks bottom and right corner of the UI element
UiObjectNotFoundException | |
UiObjectNotFoundException |
Long clicks on the top and left corner of the UI element
UiObjectNotFoundException | |
UiObjectNotFoundException |
Performs a multi-touch gesture. You must specify touch coordinates for
at least 2 pointers. Each pointer must have all of its touch steps
defined in an array of MotionEvent.PointerCoords
. You can use this method to
specify complex gestures, like circles and irregular shapes, where each
pointer may take a different path.
To create a single point on a pointer's touch path:
PointerCoords p = new PointerCoords();
p.x = stepX;
p.y = stepY;
p.pressure = 1;
p.size = 1;
touches | represents the pointers' paths. Each MotionEvent.PointerCoords
array represents a different pointer. Each MotionEvent.PointerCoords in an
array element represents a touch point on a pointer's path. |
---|
true
if all touch events for this gesture are injected successfully,
false
otherwiseGenerates a two-pointer gesture with arbitrary starting and ending points.
startPoint1 | start point of pointer 1 |
---|---|
startPoint2 | start point of pointer 2 |
endPoint1 | end point of pointer 1 |
endPoint2 | end point of pointer 2 |
steps | the number of steps for the gesture. Steps are injected about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete. |
true
if all touch events for this gesture are injected successfully,
false
otherwisePerforms a two-pointer gesture, where each pointer moves diagonally toward the other, from the edges to the center of this UiObject .
percent | percentage of the object's diagonal length for the pinch gesture |
---|---|
steps | the number of steps for the gesture. Steps are injected about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete. |
true
if all touch events for this gesture are injected successfully,
false
otherwiseUiObjectNotFoundException | |
UiObjectNotFoundException |
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.
percent | percentage of the object's diagonal length for the pinch gesture |
---|---|
steps | the number of steps for the gesture. Steps are injected about 5 milliseconds apart, so 100 steps may take around 0.5 seconds to complete. |
true
if all touch events for this gesture are injected successfully,
false
otherwiseUiObjectNotFoundException | |
UiObjectNotFoundException |
Sets the text in an editable field, after clearing the field's content.
The UiSelector
selector of this object must reference a UI element that is editable.
When you call this method, the method sets focus on the editable field, clears its existing content, then injects your specified text into the field.
If you want to capture the original contents of the field, call getText()
first.
You can then modify the text and use this method to update the field.
Improvements: Post API Level 19 (KitKat release), the underlying implementation is updated to a dedicated set text accessibility action, and it also now supports Unicode.
text | string to set |
---|
UiObjectNotFoundException | |
UiObjectNotFoundException |
Performs the swipe down action on the UiObject. The swipe gesture can be performed over any surface. The targeted UI element does not need to be scrollable. See also:
steps | indicates the number of injected move steps into the system. Steps are injected about 5ms apart. So a 100 steps may take about 1/2 second to complete. |
---|
UiObjectNotFoundException | |
UiObjectNotFoundException |
Performs the swipe left action on the UiObject. The swipe gesture can be performed over any surface. The targeted UI element does not need to be scrollable. See also:
steps | indicates the number of injected move steps into the system. Steps are injected about 5ms apart. So a 100 steps may take about 1/2 second to complete. |
---|
UiObjectNotFoundException | |
UiObjectNotFoundException |
Performs the swipe right action on the UiObject. The swipe gesture can be performed over any surface. The targeted UI element does not need to be scrollable. See also:
steps | indicates the number of injected move steps into the system. Steps are injected about 5ms apart. So a 100 steps may take about 1/2 second to complete. |
---|
UiObjectNotFoundException | |
UiObjectNotFoundException |
Performs the swipe up action on the UiObject. See also:
steps | indicates the number of injected move steps into the system. Steps are injected about 5ms apart. So a 100 steps may take about 1/2 second to complete. |
---|
UiObjectNotFoundException | |
UiObjectNotFoundException |
Waits a specified length of time for a view to become visible. This method waits until the view becomes visible on the display, or until the timeout has elapsed. You can use this method in situations where the content that you want to select is not immediately displayed.
timeout | the amount of time to wait (in milliseconds) |
---|
Waits a specified length of time for a view to become undetectable.
This method waits until a view is no longer matchable, or until the
timeout has elapsed.
A view becomes undetectable when the UiSelector
of the object is
unable to find a match because the element has either changed its state or is no
longer displayed.
You can use this method when attempting to wait for some long operation
to compete, such as downloading a large file or connecting to a remote server.
timeout | time to wait (in milliseconds) |
---|
Finds a matching UI element in the accessibility hierarchy, by using the selector for this UiObject.
timeout | in milliseconds |
---|