UiObject2介绍
来源:互联网 发布:天刀捏脸数据存多个 编辑:程序博客网 时间:2024/05/23 13:50
基础动作模拟API
<R> R
clickAndWait(EventCondition<R> condition, long timeout)
点击一个对象,然后等待在超时时间内条件成立则通过,否则抛出异常 void drag(Point dest, int speed) 自定义速度拖拽一个对象到指定位置,速度:像素/秒 void drag(Point dest) 拖拽一个对象到指定位置 void longClick() 长时间点击对象 boolean scroll(Direction direction, float percent) 滚动操作 boolean scroll(Direction direction, float percent, int speed) 自定义速度的滚动操作 void setText(String text) 设置文本内容手势动作API
组件属性API
层级关系API
List<UiObject2>
findObjects(BySelector selector) 在该对象层级之下,返回所有匹配的对象 List<UiObject2>
getChildren() 返回该对象的所有子元素的集合 UiObject2 getParent() 返回该对象的父元素 int getChildCount() 返回该对象的直接子元素的数量条件判断API
<R> R
wait(UiObject2Condition<R> condition, long timeout)
等待的条件得到满足 <R> R
wait(SearchCondition<R> condition, long timeout)
等待的条件得到满足示例代码:
package mqqzt.myuitest5;import android.app.Instrumentation;import android.graphics.Point;import android.support.test.InstrumentationRegistry;import android.support.test.runner.AndroidJUnit4;import android.support.test.uiautomator.By;import android.support.test.uiautomator.Direction;import android.support.test.uiautomator.UiDevice;import android.support.test.uiautomator.UiObject2;import android.support.test.uiautomator.Until;import android.util.Log;import android.widget.ListView;import android.widget.TextView;import org.junit.Before;import org.junit.Test;import org.junit.runner.RunWith;import java.util.List;/** * Created by mqqzt-yang on 2015/11/22. */@RunWith(AndroidJUnit4.class)public class UiObject2Test { UiDevice uiDevice; Instrumentation instrumentation; @Before public void setUp(){ instrumentation = InstrumentationRegistry.getInstrumentation(); uiDevice = UiDevice.getInstance(instrumentation); } @Test public void testSetText(){ UiObject2 mmsSendObject = uiDevice.findObject(By.res("com.android.mms:id/embedded_text_editor")); mmsSendObject.setText("我的东西在哪里?"); sleep(1000); mmsSendObject.clear(); } @Test public void testDrag(){ UiObject2 settingsObj = uiDevice.findObject(By.text("Settings")); Point p = new Point(); p.x = 116; p.y = 497; settingsObj.drag(p, 500); sleep(2000); settingsObj.clickAndWait(Until.newWindow(), 5000); } @Test public void testScroll(){ UiObject2 listViewObj = uiDevice.findObject(By.clazz(ListView.class)); listViewObj.scroll(Direction.DOWN, 0.8f, 500); } @Test public void testPinch(){ UiObject2 viewObj = uiDevice.findObject(By.res("com.android.gallery3d:id/gl_root_view")); viewObj.pinchClose(0.8f, 500); sleep(2000); viewObj.pinchOpen(0.8f, 500); } @Test public void testFling(){ UiObject2 msg = uiDevice.findObject(By.res("com.android.contacts:id/message")); msg.fling(Direction.LEFT, 500); } @Test public void testSwipe(){ UiObject2 msg = uiDevice.findObject(By.res("com.android.contacts:id/message")); msg.swipe(Direction.RIGHT, 0.8f, 500); } @Test public void testWifiSwitch(){ UiObject2 wifiSwitchObj = uiDevice.findObject(By.res("com.android.settings:id/switch_widget")); if(!wifiSwitchObj.isChecked()){ wifiSwitchObj.click(); } } @Test public void testChild(){ UiObject2 listViewObj = uiDevice.findObject(By.clazz(ListView.class)); UiObject2 child = listViewObj.findObject(By.clazz(TextView.class)); Log.i("mqqzt", child.getText()); List<UiObject2> listChild = listViewObj.findObjects(By.clazz(TextView.class)); Log.i("mqqzt", listChild.size() + ""); for(UiObject2 uiObject2 : listChild){ Log.i("mqqzt", uiObject2.getText()); } List<UiObject2> getChild = listViewObj.getChildren(); Log.i("mqqzt", getChild.size() + ""); for(UiObject2 uiObject2 : getChild){ Log.i("mqqzt", uiObject2.getClassName()); } Log.i("mqqzt", listViewObj.getParent().getClassName()); Log.i("mqqzt", listViewObj.getChildCount() + ""); UiObject2 childEqual = listViewObj.findObject(By.text("Alarms")); Log.i("mqqzt", child.equals(childEqual) + ""); Log.i("mqqzt", child.hasObject(By.text("Alarms")) + ""); Log.i("mqqzt", child.hasObject(By.text("Alarms12")) + ""); childEqual.recycle(); childEqual = listViewObj.findObject(By.text("Alarms")); childEqual.click(); } public void sleep(int sleep){ try { Thread.sleep(sleep); } catch (InterruptedException e) { e.printStackTrace(); } }}
0 0
- UiObject2介绍
- UiObject2简介
- UiObject2 API的简单译文
- Uiautomator 2.0之UiObject2类学习小记
- uiautomator 之uiautomator 2.0 UiObject2学习收藏
- UIAutomator2.0详解(By & BySelector & UIObject2 VS UISelector & UIObject)
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- 介绍
- ubuntu 14.04 终端 打开文件编辑 i使用不了 不能插入了
- Python小知识备忘录
- SSH返回Json格式的数据
- 最优合并问题
- Google Protocol Buffer 的使用和原理
- UiObject2介绍
- 如何定义和实现一个类的成员函数为回调函数
- 最小环(floyd)
- nyoj+dfs搜索+vector二维数组+典型的递归模板需要慢慢领悟
- C/C++学习总结(复习)
- php中curl的参数详解
- Hibernate 映射关系 ---Many2Many 双向关联
- 对象序列化(二进制序列化)
- Received CISSP certificate and ID card