R
- the type of the raw element this class wraps, for example, View or
AccessibilityNodeInfoE
- the type of the concrete subclass of BaseUiElementpublic abstract class BaseUiElement<R,E extends BaseUiElement<R,E>> extends java.lang.Object implements UiElement
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ATTRIB_NOT_VISIBLE |
static java.lang.String |
ATTRIB_VISIBLE_BOUNDS |
Constructor and Description |
---|
BaseUiElement() |
Modifier and Type | Method and Description |
---|---|
void |
click()
Clicks this element.
|
protected boolean |
doPerform(Action action) |
protected abstract void |
doPerformAndWait(java.util.concurrent.FutureTask<java.lang.Boolean> futureTask,
long timeoutMillis) |
void |
doubleClick()
Double-clicks this element.
|
<T> T |
get(Attribute attribute) |
protected abstract java.util.Map<Attribute,java.lang.Object> |
getAttributes() |
android.graphics.Rect |
getBounds()
Gets the UiElement bounds in screen coordinates.
|
protected abstract java.util.List<E> |
getChildren() |
java.util.List<E> |
getChildren(Predicate<? super UiElement> predicate)
Gets an immutable
List of immediate children that satisfy
predicate . |
java.lang.String |
getClassName()
Gets the class name of the underlying view.
|
java.lang.String |
getContentDescription()
Gets the content description of this element.
|
java.lang.String |
getPackageName()
Gets the package name of this element.
|
abstract R |
getRawElement()
Gets the raw element used to create this UiElement.
|
java.lang.String |
getResourceId()
Gets the resource id of this element.
|
int |
getSelectionEnd() |
int |
getSelectionStart() |
java.lang.String |
getText()
Gets the text of this element.
|
boolean |
hasSelection() |
boolean |
isCheckable() |
boolean |
isChecked() |
boolean |
isClickable() |
boolean |
isEnabled() |
boolean |
isFocusable() |
boolean |
isFocused() |
boolean |
isLongClickable() |
boolean |
isPassword() |
boolean |
isScrollable() |
boolean |
isSelected() |
void |
longClick()
Long-clicks this element.
|
boolean |
perform(Action action)
Executes the given action.
|
void |
scroll(Direction.PhysicalDirection direction)
Scrolls in the given direction.
|
void |
setText(java.lang.String text)
Sets the text of this element.
|
void |
setUiElementActor(UiElementActor uiElementActor) |
void |
setValidator(Validator validator)
Sets the validator to check when
perform(Action) is called. |
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getInjector, getParent, getVisibleBounds, isVisible
public static final java.lang.String ATTRIB_VISIBLE_BOUNDS
public static final java.lang.String ATTRIB_NOT_VISIBLE
public <T> T get(Attribute attribute)
public java.lang.String getText()
UiElement
public java.lang.String getContentDescription()
UiElement
getContentDescription
in interface UiElement
public java.lang.String getClassName()
UiElement
getClassName
in interface UiElement
ViewElement.overrideClassName(java.lang.String, java.lang.String)
public java.lang.String getResourceId()
UiElement
getResourceId
in interface UiElement
public java.lang.String getPackageName()
UiElement
getPackageName
in interface UiElement
public boolean isCheckable()
isCheckable
in interface UiElement
public boolean isChecked()
public boolean isClickable()
isClickable
in interface UiElement
public boolean isEnabled()
public boolean isFocusable()
isFocusable
in interface UiElement
public boolean isFocused()
public boolean isScrollable()
isScrollable
in interface UiElement
public boolean isLongClickable()
isLongClickable
in interface UiElement
public boolean isPassword()
isPassword
in interface UiElement
public boolean isSelected()
isSelected
in interface UiElement
public android.graphics.Rect getBounds()
UiElement
public int getSelectionStart()
public int getSelectionEnd()
public boolean hasSelection()
public boolean perform(Action action)
UiElement
protected boolean doPerform(Action action)
protected abstract void doPerformAndWait(java.util.concurrent.FutureTask<java.lang.Boolean> futureTask, long timeoutMillis)
public void setText(java.lang.String text)
UiElement
If this element already has text, it is cleared first if the device has API 11 or higher.
TODO: Support this behavior on older devices.
The IME
(soft keyboard) may be shown after this call. If the text
ends with '\n'
, the
IME may be closed automatically. If the IME is open, you can call UiDevice.pressBack()
to close it.
If you are using InstrumentationDriver
,
you may use CloseKeyboardAction
to close it. The
advantage of CloseKeyboardAction
is that it is a no-op if the IME is hidden. This is
useful when the state of the IME cannot be determined.
public void click()
UiElement
public void longClick()
UiElement
public void doubleClick()
UiElement
doubleClick
in interface UiElement
public void scroll(Direction.PhysicalDirection direction)
UiElement
protected abstract java.util.Map<Attribute,java.lang.Object> getAttributes()
protected abstract java.util.List<E> getChildren()
public java.util.List<E> getChildren(Predicate<? super UiElement> predicate)
UiElement
List
of immediate children that satisfy
predicate
. It always filters children that are null. This gives a
low level access to the underlying data. Do not use it unless you are sure
about the subtle details. Note the count may not be what you expect. For
instance, a dynamic list may show more items when scrolling beyond the end,
varying the count. The count also depends on the driver implementation:
InstrumentationDriver
includes all.UiAutomationDriver
depends on)
does not include off-screen children, but may include invisible on-screen
children.
Another discrepancy between InstrumentationDriver
UiAutomationDriver
is the order of children. The Accessibility API
returns children in the order of layout (see
ViewGroup.addChildrenForAccessibility(java.util.ArrayList<android.view.View>)
, which is added
in API16).
getChildren
in interface UiElement
public java.lang.String toString()
toString
in class java.lang.Object
public abstract R getRawElement()
public void setUiElementActor(UiElementActor uiElementActor)
public void setValidator(Validator validator)
perform(Action)
is called.