Android无线测试之—UiAutomator UiCollection API介绍
UiCollection类介绍
一、UiCollection类说明
1)UiCollection类是UiObject类的子类,即UiObject类的所有方法都被UiCollection继承下来了,都可以使用
2)UiCollection代表元素条目的集合
二、UiCollection功能说明
1)先按照一定的条件枚举出容器类界面所有符合条件的子元素
2)再从符合条件的元素的和集中再次通过一定的条件最终定位需要的组件
三、UiCollection使用场景
1)一般使用容器类组件作为父类
2)一般用在需要找子类,且子类由于某些原因不好定位
3)获取某一类的数量,如获取联系人列表下当前试图下联系人的数量
四、相关API介绍:
1、从集合中查找对象:
1)相应API介绍:
| 返回值 | API |
| UiObject | getChildByText(UiSelector childPattern, String text) |
| UiObject | getChildByDescription(UiSelector childPattern, String text) |
| UiObject | getChildByInstance(UiSelector childPattern, int instance) |
在UiSelector选择器的查找条件中从子ui元素中搜索,递归搜索所有符合条件的子集。
再次用文本/描述/实例条件从前面搜索子集定位到想要的元素。
2)参数说明
childPattern UiSelector从子元素的选择条件
text、instance 从子元素中再次用文本/描述/实例条件搜素元素
3)返回值
UiObject
4)抛出异常
UiObjectNotFondException
5)API应用举例
package com.test.uicollection; import android.view.KeyEvent; import com.android.uiautomator.core.UiCollection;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase; public class Demo extends UiAutomatorTestCase { /**
* @param args
*/
public static void main(String[] args) {
String jarName, testClass, testName, androidID;
jarName="demo";
testClass="com.test.uicollection.Demo";
testName="testInstance";
androidID="1";
new UiAutomatorHelper(jarName, testClass, testName, androidID); } public void testText() throws UiObjectNotFoundException{
UiDevice.getInstance().pressHome();
sleep(2000);
UiObject apps=new UiObject(new UiSelector().description("Apps"));
apps.click();
sleep(2000);
UiObject fileManage=new UiObject(new UiSelector().text("File Manager"));
fileManage.click();
sleep(2000);
UiCollection collection=new UiCollection(new UiSelector().className("android.widget.ListView"));
UiSelector childPattern=new UiSelector().className("android.widget.TextView");
String text="Movies";
UiObject music=collection.getChildByText(childPattern, text);
music.click();
} public void testDesc() throws UiObjectNotFoundException{
UiDevice.getInstance().pressHome();
sleep(2000);
UiObject phone=new UiObject(new UiSelector().text("Phone"));
phone.click();
sleep(2000);
UiCollection collection=new UiCollection(new UiSelector().className("android.widget.TableLayout")); UiSelector childPattern=new UiSelector().className("android.widget.ImageButton");
String text="one"; UiObject button=collection.getChildByDescription(childPattern, text);
button.click();
sleep(500);
} public void testInstance() throws UiObjectNotFoundException{
UiDevice.getInstance().pressHome();
sleep(2000);
UiObject phone=new UiObject(new UiSelector().text("Phone"));
phone.click();
sleep(2000);
UiObject editText=new UiObject(new UiSelector().resourceId("com.android.dialer:id/digits"));
UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_MOVE_END);
String text=editText.getText();
System.out.println("THE TEXT IS: "+text);
while(editText.getText()!=""){
UiDevice.getInstance().pressKeyCode(KeyEvent.KEYCODE_DEL);
} UiCollection collection=new UiCollection(new UiSelector().className("android.widget.TableLayout"));
UiSelector childPattern=new UiSelector().className("android.widget.ImageButton");
UiObject one=collection.getChildByInstance(childPattern, 0);
UiObject zero=collection.getChildByInstance(childPattern, 10);
UiObject eight=collection.getChildByInstance(childPattern, 7);
UiObject six=collection.getChildByInstance(childPattern, 5); one.click();
sleep(500);
zero.click();
sleep(500);
zero.click();
sleep(500);
eight.click();
sleep(500);
six.click();
sleep(500); } }
Demo.java
2、获取某种搜索条件组件的数量
1)相应API介绍
public int getChildCount(UiSelector childPattern)
按照UiSelector查找条件递归查找所有符合条件的子子孙孙集合的数量
public int getChildCount()
仅直接查找符合条件的子类的数量(不涉及后代)
2)参数说明
childPattern 选择条件
3)返回值
int 符合条件的子子孙孙集合的数量
4)API应用举例
package com.test.uicollection; import android.view.KeyEvent; import com.android.uiautomator.core.UiCollection;
import com.android.uiautomator.core.UiDevice;
import com.android.uiautomator.core.UiObject;
import com.android.uiautomator.core.UiObjectNotFoundException;
import com.android.uiautomator.core.UiSelector;
import com.android.uiautomator.testrunner.UiAutomatorTestCase; public class Demo extends UiAutomatorTestCase { /**
* @param args
*/
public static void main(String[] args) {
String jarName, testClass, testName, androidID;
jarName="demo";
testClass="com.test.uicollection.Demo";
testName="testCount";
androidID="1";
new UiAutomatorHelper(jarName, testClass, testName, androidID); } public void testCount() throws UiObjectNotFoundException{
UiDevice.getInstance().pressHome();
sleep(2000);
UiObject phone=new UiObject(new UiSelector().text("Phone"));
phone.click();
sleep(2000); //getChildCount(UiSelector childPattern) 递归查找后代中所有符合条件的元素的数量
UiCollection collection=new UiCollection(new UiSelector().className("android.widget.TableLayout"));
UiSelector childPattern=new UiSelector().className("android.widget.ImageButton");
int imageButtonCount=collection.getChildCount(childPattern);
System.out.println("ImageButtonCount="+imageButtonCount); //getChildCount() 仅查找子类中符合条件的元素数量
UiCollection tableCcollection=new UiCollection(new UiSelector().className("android.widget.TableLayout"));
int tableImageButtonCount=tableCcollection.getChildCount();
System.out.println("TableImageButtonCount="+tableImageButtonCount);
} }
Demo.java
Android无线测试之—UiAutomator UiCollection API介绍的更多相关文章
- Android无线测试之—UiAutomator UiScrollable API介绍三
获取列表子元素 一.相关API介绍 返回值 API 描述 UiObject getChildByDescription(UiSelector childPattern, String text, bo ...
- Android无线测试之—UiAutomator UiObject API介绍六
手势操作 1.手势相关操作 2.相关API介绍 返回值 API 描述 boolean performMultiPointerGesture(PointerCoords[]... touches) 执行 ...
- Android无线测试之—UiAutomator UiDevice API介绍八
获取包名.开启通知栏.快速设置.获取布局文件的方法 一.包名.通知栏.快速设置.布局文件等相关知识: 1)包名:标示应用的符号,每个应用的名字 2)通知栏:从主界面的顶端向下拉,就可以打开通知栏 3) ...
- Android无线测试之—UiAutomator UiDevice API介绍四
拖拽与滑动 一.概念介绍: 1)拖拽:将组建从一个坐标移动到另一个坐标 2)移动:从一二坐标点移动到另一个坐标点 3)步长:从一点滑动到另一点使用的时间 二.拖拽与滑动的相关API: 返回值 方法名 ...
- Android无线测试之—UiAutomator UiScrollable API介绍八
设置滚动方向 一.设置滚动方向相关API 返回值 API 描述 UiScrollable setAsHorizontalList 设置滚动方向为水平滚动 UiScrollable setAsVerti ...
- Android无线测试之—UiAutomator UiScrollable API介绍七
滑动到某个对象 一.滑动到某个对象相关API 返回值 API 描述 boolean scrollIntoView(UiSelector selector) 滑动到条件元素所在位置,并且尽量让其居于屏幕 ...
- Android无线测试之—UiAutomator UiScrollable API介绍六
向前与向后滚动API 一.向前与向后滚动相关API 返回值 API 描述 boolean scrollBackward(int steps) 自动以步长向后滑动 boolean scrollBackw ...
- Android无线测试之—UiAutomator UiScrollable API介绍五
滑动区域校准常量设置与获取 一.校准概念 校准常量指的是:滑动操作坐标时的偏移量,用来取偏移比例 二.相关API 返回值 API 描述 double getSwipeDeadZonePercentag ...
- Android无线测试之—UiAutomator UiScrollable API介绍四
获取与设置最大滚动次数常量值 一.获取与设置最大滚动次数常量值相关API 返回值 API 描述 int getMaxSearchSwipes() 获取执行搜索滑动过程中的最大滑动次数,默认最大滚动次数 ...
随机推荐
- 类非静态成员的函数指针 的使用 Function pointer of a non-static member function of a class
you can get the pointer of the method, but it has to be called with an object typedef void (T::*Meth ...
- scott权限
有时scott数据被破坏了 可以回复 以下为 安装路径 dos下 @G:\app\Administrator\product\11.2.0\dbhome_1\RDBMS\ADMIN\scott. ...
- 插入排序(PHP,C)
PHP<?php /* ** 功能:插入算法 ** 描述: ** 作者:yuwensong */ function insertSorting($arr,$n){ for($i = 1; $i& ...
- 修改select下拉框的下拉按钮
ie上的下拉框下拉按钮真是太丑了,如何把他自定义一下呢? 首先,把浏览器自带的下拉框去掉: select::-ms-expand { display: none; } 接下来,用自己喜欢的下拉图片去 ...
- Asp.Net MVC之防止用户注入脚本参数
假设有一个Controller,代码如下: public string Browse(string genre) { string message = "Store.Browse, Genr ...
- Python sklearn 分类效果评估
https://blog.csdn.net/sinat_26917383/article/details/75199996
- iis支持IPA和APK文件下载
找到IIS 扩展名是:.apk MIMI类型是:application/vnd.android.package-archive扩展名是:.ipa MIMI类型是:application/iphone
- Mac 學習系列之Python Challenge 11-20
11.给你一个正整数列表 L, 如 L=[2,8,3,50], 输出L内全部数字的乘积末尾0的个数, 如例子L的结果为2.(提示:不要直接相乘,数字非常多,可能溢出) Answer: n_2 = 0 ...
- WebSocket遇到的一些问题
一 .Nginx配置websocket 为了解决Nginx转发不能进行websocket通信问题 将nginx配置文件添加如下内容: map $http_upgrade $connection ...
- windows共享文件的方法
众所周知,一个宿舍,一个公司处在一个局域网络中,在不能使用外网通信情况下,此时,我们忘带U盘或者硬盘,同学或同事之间需要拷贝资料或者数据,是不是就不能实现了呢?答案是否定的.微软为了解决这种不必要的麻 ...