1.点击与长按

void click()

Clicks on this object.

void click(long duration)

Performs a click on this object that lasts for duration milliseconds.

<R> R clickAndWait(EventCondition<R> condition, long timeout)

Clicks on this object, and waits for the given condition to become true.

void longClick()

Performs a long click on this object.

2.拖拽与滑动

void drag(Point dest)

Drags this object to the specified location.

void drag(Point dest, int speed)

Drags this object to the specified location.

void swipe(Direction direction, float percent, int speed)

Performs a swipe gesture on this object.

void swipe(Direction direction, float percent)

Performs a swipe gesture on this object.

3.输入文本与清除文本

void setText(String text)

Sets the text content if this object is an editable field.

void clear()

Clears the text content if this object is an editable field.

如clear()不起作用,可采取

//将光标移动到文字末尾,按backspace

//将光标移动到文本开头,按del

4.获取对象属性

String getApplicationPackage()

Returns the package name of the app that this object belongs to.

int getChildCount()

Returns the number of child elements directly under this object.

List<UiObject2> getChildren()

Returns a collection of the child elements directly under this object.

String getClassName()

Returns the class name of the underlying View represented by this object.

String getContentDescription()

Returns the content description for this object.

UiObject2 getParent()

Returns this object's parent.

String getResourceName()

Returns the fully qualified resource name for this object's id.

String getText()

Returns the text value for this object.

Rect getVisibleBounds()

Returns the visible bounds of this object in screen coordinates.

Point getVisibleCenter()

Returns a point in the center of the visible bounds of this object.

5.属性判断:

boolean isCheckable()

Returns whether this object is checkable.

boolean isChecked()

Returns whether this object is checked.

boolean isClickable()

Returns whether this object is clickable.

boolean isEnabled()

Returns whether this object is enabled.

boolean isFocusable()

Returns whether this object is focusable.

boolean isFocused()

Returns whether this object is focused.

boolean isLongClickable()

Returns whether this object is long clickable.

boolean isScrollable()

Returns whether this object is scrollable.

boolean isSelected()

Returns whether this object is selected.

6.模拟手势操作

双指缩放

void pinchClose(float percent)

Performs a pinch close gesture on this object.

void pinchClose(float percent, int speed)

Performs a pinch close gesture on this object.

void pinchOpen(float percent)

Performs a pinch open gesture on this object.

void pinchOpen(float percent, int speed)

Performs a pinch open gesture on this object.

其他

boolean fling(Direction direction, int speed)

Performs a fling gesture on this object.

boolean fling(Direction direction)

Performs a fling gesture on this object.

boolean scroll(Direction direction, float percent, int speed)

Performs a scroll gesture on this object.

boolean scroll(Direction direction, float percent)

Performs a scroll gesture on this object.

void setGestureMargin(int margin)

Sets the margins used for gestures in pixels.

void setGestureMargins(int left, int top, int right, int bottom)

Sets the margins used for gestures in pixels.

7.判断对象是否存在

boolean hasObject(BySelector selector)

Returns whether there is a match for the given criteria under this object.

8.获取该对象

UiObject2 findObject(BySelector selector)

Searches all elements under this object and returns the first object to match the criteria.

List<UiObject2> findObjects(BySelector selector)

Searches all elements under this object and returns all objects that match the criteria.

9.等待

<R> R wait(UiObject2Condition<R> condition, long timeout)

Waits for given the condition to be met.

<R> R wait(SearchCondition<R> condition, long timeout)

Waits for given the condition to be met.

UiAutomator -- UiObject2 API的更多相关文章

  1. Android无线测试之—UiAutomator UiScrollable API介绍八

    设置滚动方向 一.设置滚动方向相关API 返回值 API 描述 UiScrollable setAsHorizontalList 设置滚动方向为水平滚动 UiScrollable setAsVerti ...

  2. Android无线测试之—UiAutomator UiScrollable API介绍七

    滑动到某个对象 一.滑动到某个对象相关API 返回值 API 描述 boolean scrollIntoView(UiSelector selector) 滑动到条件元素所在位置,并且尽量让其居于屏幕 ...

  3. Android无线测试之—UiAutomator UiScrollable API介绍六

    向前与向后滚动API 一.向前与向后滚动相关API 返回值 API 描述 boolean scrollBackward(int steps) 自动以步长向后滑动 boolean scrollBackw ...

  4. Android无线测试之—UiAutomator UiScrollable API介绍五

    滑动区域校准常量设置与获取 一.校准概念 校准常量指的是:滑动操作坐标时的偏移量,用来取偏移比例 二.相关API 返回值 API 描述 double getSwipeDeadZonePercentag ...

  5. Android无线测试之—UiAutomator UiScrollable API介绍四

    获取与设置最大滚动次数常量值 一.获取与设置最大滚动次数常量值相关API 返回值 API 描述 int getMaxSearchSwipes() 获取执行搜索滑动过程中的最大滑动次数,默认最大滚动次数 ...

  6. Android无线测试之—UiAutomator UiScrollable API介绍三

    获取列表子元素 一.相关API介绍 返回值 API 描述 UiObject getChildByDescription(UiSelector childPattern, String text, bo ...

  7. Android无线测试之—UiAutomator UiScrollable API介绍二

    快速滑动 一.快速滑动相关概念 1.步长:从一点滑动到另一点所用的时间 2.扫动次数:例如列表,要滑动多少次才能到底部,这个滑动次数就是扫动次数 二.相关API 返回值 API 描述 boolean ...

  8. Android无线测试之—UiAutomator UiObject API介绍七

    判断对象是否存在 1.判断对象是否存在相关API 返回值 API 描述 boolean waitForExists(long timeout) 等待对象出现 boolean waitUntilGone ...

  9. Android无线测试之—UiAutomator UiCollection API介绍

    UiCollection类介绍 一.UiCollection类说明 1)UiCollection类是UiObject类的子类,即UiObject类的所有方法都被UiCollection继承下来了,都可 ...

随机推荐

  1. JavaScript中的 prototype 和 constructor

    prototype属性  任何js函数都可以用作构造函数, 而构造函数需要用到prototype属性, 因此, 每个js函数F(除了ES5的Function.bind()方法返回的函数外) 都自动拥有 ...

  2. 201.09.22 除虫药水(线性dp)

    描述 在十年前,除虫是十分艰苦的工作.那时,使用普通药水进行除虫的效果极差,在一片苹果 林中使用后除掉的虫仅为极小一部分. 比如说,Bugs 镇共有 N 片苹果林,对第i 片使用普通药水可以除掉 ai ...

  3. 2018.08.30 NOIP模拟 graph(dfs序/树剖+线段树)

    [描述] 给你一个图,一共有 N 个点,2*N-2 条有向边. 边目录按两部分给出 1. 开始的 n-1 条边描述了一颗以 1 号点为根的生成树,即每个点都可以由 1 号点 到达. 2. 接下来的 N ...

  4. Spring MVC之@RequestMapping 传递数组

    1.前台: var param = {titles:['col1','col2','col3']}; $.ajax({url:url, type:"post", data:para ...

  5. *C语言的小技巧

    计算数组长度 ,,,,}; int Length=sizeof(a)/sizeof(int); 交换a和b的值,不借用辅助变量 a=a+b; b=a-b; a=a-b; 将0-9的字符转化为整数 '; ...

  6. TensorFlow入门案例

    入门小案例,分别是回归模型建立和mnist数据集的模型建立 1.回归案例: import tensorflow as tf import numpy as np from tensorflow.exa ...

  7. 使用for in循环遍历json对象的数据

    使用for in遍历json对象数据,如果数据中的名称有为数字的话,只对正整数有效,那么先会输出为正整数的数据,后面其他的会按照原来数据中定义的顺序不变输出. 针对名称为数字的json对象数据进行测试 ...

  8. Android-Java卖票案例-推荐此方式Runnable

    上一篇博客 Android-卖票案例static-不推荐此方式,讲解了卖票案例是 private static int ticket = 10;,static静态的这种方式来解决卖票多卖30张的问题, ...

  9. eclipse/myeclipse介绍

    eclipse更加纯净,比较简洁,需要某些插件的时候,需要自己去配置才可以,而myeclipse自带了很多的插件功能更为强大. 在eclipse于myeclipse创建的项目是有差异的,eclipse ...

  10. golang array, slice, string笔记

    本来想写一篇关于golang io的笔记,但是在学习io之前必须了解array, slice, string概念,因此将在下篇写golang io.   array: 数组的长度是该数组类型的一部分, ...