UiAutomator2

上一篇 / 下一篇  2018-11-05 16:00:35 / 个人分类:UiAutomator

。。。。。。。。。。。。。。。。。。。。。上接UiAutomator1。。。。。。。。。。。。。。。。。。。。。


⑤ UiCollection控件定位器:继承自UiObject

3种调用方式:UiCollection对象假设为collection

// 两个参数一个是UiSelector参数,一个可以指定为描述或者文本或者实例条件。

方式1:collection.getChildByDescription(childPattern,text);

方式2:collection.getChildByInstance(childPattern,instance);

方式3:collection.getChildByText(childPattern,text);

 

原理:

从业务流程分析(如我要打开应用QQ、QQ在文件夹“聊天”下,而文件夹在当前页----如图)

那我们就可以将这四个作为一个集合。


 

代码如:

//1.通过类名获取所有组件的集合

UiCollection collection = new UiCollection(new UiSelector().className("android.view.ViewGroup").instance(0));

//2.通过类名对步骤1中的集合进行筛选

UiObject obj_chat = collection.getChildByDespriton(

new UiSelector().className("android.widget.LinearLayout").index(3),"聊天");

//3.点击“聊天”文件夹    

obj_chat.click();

⑥ UiAutomatorTestCase

每个测试用例都需要继承UiAutomatorTestCase,以实现测试环境的setup,teardown等功能。而UiAutomatorTestCase则是通过继承Junit3中的TestCase类,并调用其中的setUp() tearDown() getParams() 函数。其中主要是用Bundle实现Android Activity之间的通讯。在UiAutomatorTestCase,还加入了getUiDevice()等关于UiDevice函数,以实现在测试的任意地方均可调用UiDevice() 

5、关于断言:

为了确认某一个对象是否被成功获得,加入断言语句:

代码如:

UiObject new_target1 = new UiObject(new UiSelector().resourceId("com.tencent.mobileqq:id/name"));

assertTrue("HAS BEEN NOT FOUND",new_target1.exists());

System out println("The icon has been found!");

new_target1.click();

6、UI Auromator测试用例继承自UiAutomatorTestCase类,UiAutomatorTestCase类继承自junit.framwork.TestCase类,所以可以用JunitAssert类来比较测试结果。

7、sleep(1000); 延时1秒钟,此处要与Appium中区分开

8、搜集的比较好的链接汇总:

   以编程的思维考虑:https://blog.csdn.net/fhaohaizi/article/details/77941155

   截图对于图片大小的处理:https://blog.csdn.net/u011277123/article/details/53535296

   常用API整理:http://www.cnblogs.com/fnng/p/9291855.html

   查漏补缺:http://www.cnblogs.com/by-dream/p/4996000.html

 


TAG:

 

评分:0

我来说两句

Open Toolbar