Android+uiautomator函数方法(2)

11、根据title匹配控件
UiObject xxxx = new UiObject(new UiSelector().description("xxx"));


12、根据k值匹配
UiObject xxxx = new UiObject(new UiSelector().text("xxx"));


13、根据name查询控件
UiObject xxxx = new UiObject(new UiSelector().className(“xxx”);


14、滚轮拖动

getUiDevice().swipe(700, 640, 100, 640, 2);//在2秒钟内,指定坐标拖动


15、获取文本字符串
UiObject appsTab = new UiObject(new UiSelector().text("组件名字"));
appsTab.getText();


16、获取数组长度
UiScrollable xxxx = new UiScrollable(new UiSelector().scrollable(true));
xxxx.length();
//获取xxxx的数组长度


17、segmentedControls控件
UiObject segmentedControls = new UiObject(new UiSelector().text("segmentedControls控件上组件名称"));


18、slider控件
UiObject slider = new UiObject(new UiSelector().text("slider控件上组件名称"));


19、界面任意位置点击
getUiDevice().click (int x, int y); //坐标单击


20、捏合与放大
getUiDevice().swipe(700, 640, 100, 640, 2);//在2秒钟内,指定坐标的放大
getUiDevice().swipe(700, 640, 100, 640);/快速的拖拽,没有时间参数


22、scrollView定位
UiScrollable appViews = new UiScrollable(new UiSelector().scrollable(true));
appViews.setAsHorizontalList();
UiObject helperApp;
helperApp = appViews.getChildByText(new UiSelector()
.className(android.widget.TextView.class.getName()), " 智能家居"); 则若当前页面没有智能家居APP, 测试会自动滑动页面,直到“智能家居”App出现。


23、测试日志纪录
System.out.println("PASS or FAIL:xxxxxx");


25、设置设备旋转
getUiDevice().setOrientationLeft ();
模拟设备旋转到左边
getUiDevice().setOrientationNatural ();
模拟设备旋转到自然取向
getUiDevice().setOrientationRight ();
模拟设备旋转到右边


26、程序后台延时
waitForIdle (long time);
等待当前应用程序来闲置。


27、获取设备状态信息
getDisplayWidth();//获取目前显示窗口的高度
getDisplayHeight();//获取目前显示窗口的高度
getProductName();//获取正在运行的设备名称

posted @ 2020-05-12 20:14  熊猫可可Z  阅读(248)  评论(0编辑  收藏  举报