UiObject官方文档,个人翻译
来源:互联网 发布:宝信软件 600845 编辑:程序博客网 时间:2024/05/16 14:55
UiObject
extends Object
java.lang.Object ↳android.support.test.uiautomator.UiObject 继承结构
Known Direct Subclasses 已知的直接子类
Class Overview 类的简介
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 常量
protected static final int FINGER_TOUCH_HALF_WIDTH
protected static final int SWIPE_MARGIN_LIMIT
protected static final long WAIT_FOR_EVENT_TMEOUT
This constant is deprecated.
use setScrollAcknowledgmentTimeout(long)
protected static final long WAIT_FOR_SELECTOR_POLL
protected static final long WAIT_FOR_SELECTOR_TIMEOUT
This constant is deprecated.
use setWaitForSelectorTimeout(long)
protected static final long WAIT_FOR_WINDOW_TMEOUT
Public Constructors 公开的构造方法
public UiObject (UiSelector selector)
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.
Public Methods 公有方法 (API)
public void clearTextField ()
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
清除在editable上的已存在的文本内容。
Throws
public boolean click ()
Performs a click at the center of the visible bounds of the UI element represented by this UiObject.
点击一个View的中心位置
Returns
- true id successful else false
- 成功返回true,否则返回false
Throws
public 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. 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:
UiObject代表的元素View,会在中心位置执行一次点击事件,然后等待窗口过渡。 这个方法与click()的不同是,就要等待窗口。 一些窗口过渡的例子
Parameters 参数
Returns
- true if the event was triggered, else false
- 触发会返回true,否则返回false
Throws
抛出UiObjectNotFoundException
public boolean clickAndWaitForNewWindow ()
Waits for window transitions that would typically take longer than the usual default timeouts. See clickAndWaitForNewWindow(long)
Returns
- true if the event was triggered, else false
Throws
public boolean clickBottomRight ()
Clicks the bottom and right corner of the UI element
点击View的右下角
Returns
- true on success 成功会返回true
Throws
public boolean clickTopLeft ()
Clicks the top and left corner of the UI element
点击元素的左上角
Returns
- true on success
Throws
public boolean dragTo (UiObject destObj, int steps)
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.
拖拽当前object到目标UiObjecct。步数明确你的输入范围,可以影响你的拖拽速度,不同的速度会影响你的结果。使用此方法测试的时候,考虑评估不同的速度。
Parameters
Returns
- true if successful 成功会返回true
Throws
抛出UiObjectNotFoundException
public boolean dragTo (int destX, int destY, int steps)
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.
拖拽当前object到任意的坐标。 明确你的范围步数可影响拖拽速度,不同的速度影响结果。你在使用此方法的测试的时候,试着评估下不同的速度。
Parameters
Returns
- true if successful
Throws
抛出UiObjectFoundException
public boolean exists ()
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)
.
检查View存在,这个方法执行waitForExists(long)然后传入timeout是0。
Returns
- true if the view represented by this UiObject does exist
public Rect getBounds ()
Returns the view's bounds
property. See getVisibleBounds()
返回View的多边形属性
Returns
- Rect 返回一个Rect实例对象
Throws
public UiObject getChild (UiSelector selector)
Creates a new UiObject for a child view that is under the present UiObject.
创建一个UiObject用于代表父UiObject的子View
Parameters
Returns
- a new UiObject representing the child view
- 返回一个新的UiObject实例对象表示子View
Throws
public int getChildCount ()
Counts the child views immediately under the present UiObject.
用于UiObject下面有多个子View
Returns
- the count of child views.
- 返回一个UiObject拥有的子View数量
Throws
public String getClassName ()
Retrieves the className
property of the UI element.
Returns
- class name of the current node represented by this UiObject
- 当前用于表示的UiObject的class name
Throws
public String getContentDescription ()
Reads the content_desc
property of the UI element
Returns
- value of node attribute "content_desc"
- 返回xml中属性为content_desc的值
Throws
public UiObject getFromParent (UiSelector selector)
Creates a new UiObject for a sibling view or a child of the sibling view, relative to the present UiObject.
Parameters
Returns
- a new UiObject representing the matched view
- 返回一个表示过滤View之后的一个新的UiObject,其实就是返回父UiObject
Throws
public String getPackageName ()
Reads the view's package
property
Returns
- true if it is else false
- 返回View的包名
Throws
public final UiSelector getSelector ()
Debugging helper. A test can dump the properties of a selector as a string to its logs if needed. getSelector().toString();
Returns
UiSelector
- 返回一个UiSelector实例对象
public String getText ()
Reads the text
property of the UI element
Returns
- text value of the current node represented by this UiObject
- 返回当前UiObject的text内容 嘿嘿,这个方法不错哦,例如:有个Button 叫 ‘点我’,那么就会返回‘点我’了
Throws
public Rect getVisibleBounds ()
Returns the visible bounds of the view. If a portion of the view is visible, only the bounds of the visible portion are reported.
Returns
- Rect
- 返回一个多边形Rect实例对象
Throws
See Also
getBounds()
public boolean isCheckable ()
Checks if the UI element's checkable
property is currently true.
Returns
- true if it is else false
- 返回当前checkable属性,如果可以返回true,否则返回false
Throws
public boolean isChecked ()
Check if the UI element's checked
property is currently true
Returns
- true if it is else false
- 返回当前View的 check属性
Throws
public boolean isClickable ()
Checks if the UI element's clickable
property is currently true.
Returns
- true if it is else false
- 返回当前View能否点击,true代表可以点击,false代表不可点击
Throws
public boolean isEnabled ()
Checks if the UI element's enabled
property is currently true.
Returns
- true if it is else false
- 返回当前View是否已经是激活状态
Throws
public boolean isFocusable ()
Check if the UI element's focusable
property is currently true.
Returns
- true if it is else false
- 返回当前View能否获得焦点
Throws
public boolean isFocused ()
Check if the UI element's focused
property is currently true
Returns
- true if it is else false
- 返回当前View是否已经获得焦点
Throws
public boolean isLongClickable ()
Check if the view's long-clickable
property is currently true
Returns
- true if it is else false
- 返回当前View是否支持长按事件
Throws
public boolean isScrollable ()
Check if the view's scrollable
property is currently true
Returns
- true if it is else false
- 返回当前View是否可以支持滑动事件
Throws
public boolean isSelected ()
Checks if the UI element's selected
property is currently true.
Returns
- true if it is else false
- 返回当前View是否已经选择
Throws
public boolean longClick ()
Long clicks the center of the visible bounds of the UI element
Returns
- true if operation was successful
- 返回当前View是否成功响应长按事件
Throws
public boolean longClickBottomRight ()
Long clicks bottom and right corner of the UI element
Returns
- true if operation was successful
- 返回长按右下角是否成功
Throws
public boolean longClickTopLeft ()
Long clicks on the top and left corner of the UI element
Returns
- true if operation was successful
- 返回长按左上角是否成功
Throws
public boolean performMultiPointerGesture (PointerCoords... touches) 参数还是可变参数,好high,接受的是PointerCoords实力对象哦
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;
哈哈,到了手势阶段,爽了
Parameters
MotionEvent.PointerCoords
array represents a different pointer. EachMotionEvent.PointerCoords
in an array element represents a touch point on a pointer's path.Returns
true
if all touch events for this gesture are injected successfully,false
otherwise
public boolean performTwoPointerGesture (Point startPoint1, Point startPoint2, Point endPoint1, Point endPoint2, int steps)
Generates a two-pointer gesture with arbitrary starting and ending points.
Parameters
Returns
true
if all touch events for this gesture are injected successfully,false
otherwise
public 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 .
Parameters
Returns
true
if all touch events for this gesture are injected successfully,false
otherwise
Throws
public 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.
Parameters
Returns
true
if all touch events for this gesture are injected successfully,false
otherwise
Throws
public boolean setText (String text)
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.
Parameters
Returns
- true if operation is successful
Throws
public boolean swipeDown (int steps) 向下滑动
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:
scrollToBeginning(int)
scrollToEnd(int)
scrollBackward()
scrollForward()
Parameters
Returns
- true if successful 如果成功返回True
Throws
public boolean swipeLeft (int steps)
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:
scrollToBeginning(int)
scrollToEnd(int)
scrollBackward()
scrollForward()
Parameters
Returns
- true if successful
Throws
public boolean swipeRight (int steps)
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:
scrollToBeginning(int)
scrollToEnd(int)
scrollBackward()
scrollForward()
Parameters
Returns
- true if successful
Throws
public boolean swipeUp (int steps)
Performs the swipe up action on the UiObject. See also:
scrollToBeginning(int)
scrollToEnd(int)
scrollBackward()
scrollForward()
Parameters
Returns
- true of successful
Throws
public boolean waitForExists (long timeout)
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.
Parameters
Returns
- true if the view is displayed, else false if timeout elapsed while waiting
public boolean waitUntilGone (long timeout)
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.
Parameters
Returns
- true if the element is gone before timeout elapsed, else false if timeout elapsed but a matching element is still found.
- UiObject官方文档,个人翻译
- android 官方文档 个人翻译 Bluetooth 蓝牙
- 3D Touch 的官方文档翻译及个人总结
- 对官方文档中NSAutoreleasePool的个人翻译
- JNI 官方文档翻译
- FullCalendar 官方文档翻译
- monkeyrunner官方文档翻译
- FullCalendar 官方文档翻译
- FullCalendar 官方文档翻译
- NSLayoutContraint 官方文档翻译
- NSPredicate官方文档翻译
- FullCalendar 官方文档翻译
- MifareUltralight官方文档翻译
- ViewPager官方文档翻译
- NSPredicate官方文档翻译
- hbase 官方文档翻译
- Andriod官方文档翻译
- MHA官方文档翻译
- 第九周项目2-(2)对称矩阵的加法和乘法
- VC++ 6.0实用技巧汇总
- 今天大盘不好,中国高科本来涨上去了,又回来了呵呵。。。
- js中的hasOwnProperty和isPrototypeOf方法
- 64位JAVA环境配置
- UiObject官方文档,个人翻译
- 第十周项目1—二叉树的链式存储及基本运算
- 第九周项目3—稀疏矩阵的三元组表示的实现及应用(2)
- HUD 1026 纯C代码广搜
- 稀疏矩阵的三元组表示的实现(3.1)
- POJ 题目1505 Copying Books(DP,打印路径)
- mysqldump使用方法
- android 全局获取Context的技巧 《第一行代码》
- 数据库结构初探--引言