ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Java+Uiautomator自动化测试 -- UiCollection学习

2019-04-27 22:51:45  阅读:624  来源: 互联网

标签:元素 Java UiSelector UiObject childPattern UI Uiautomator UiCollection


UiAutomator1.0主要的API汇总

官网介绍:

The UI Automator APIs allow you to write robust tests without needing to know about the implementation details of the app that you are targeting. You can use these APIs to capture and manipulate UI components across multiple apps:

  • UiCollection: Enumerates a container's UI elements for the purpose of counting, or targeting sub-elements by their visible text or content-description property.
  • UiObject: Represents a UI element that is visible on the device.
  • UiScrollable: Provides support for searching for items in a scrollable UI container.
  • UiSelector: Represents a query for one or more target UI elements on a device.
  • Configurator: Allows you to set key parameters for running UI Automator tests.

UiCollection

 

一 类说明

a. UiCollection是UiObject的子类

b. UiCollection代表元素条目的集合

 

二 UiCollection功能

先按照一定的条件列举出容器中的所有符合条件UI元素,然后在这些符合条件的元素中通过其可见文本或内容描述属性对子元素进行计数或定位。

public class UiCollection extends UiObject 

继承的常量:

 androidx.test.uiautomator.UiObject

 

三 UiCollection使用场景

a. 一般使用容器类组件作为父类

b. 一般使用在需要找子类并且子类由于某些因素不好定位

c. 获取某一类的数量,比如获取短信列表下面短信的数量

 

 

四. 使用文本与描述条件从集合中查找对象

public UiObject getChildByDescription (UiSelector childPattern, String text)
pubilc UiObject getChildByText (UiSelector, childPattern, String text)
pubilc UiObject getChildByInstance (UiSelector childPattern, int instance)

如上所说,在UiSelector选择器的查找条件中从子ui元素中搜索,递归寻找所有符合条件的子集。然后用描述,文本,实例条件搜索元素。

a. childPattern:UiSelector从子元素中选择的条件

b. text,instance都是从搜索出来的元素中再次用描述,文本条件搜出来的元素。

返回值:UIObject

抛出异常:UIObjectNotFoundException

 

五. 获取某种搜索条件组合的数量

public int getChildCount(UiSelector childPattern)

按照查找条件递归的查找所有符合条件的子元素集合的数量

用法:

 

 

 

 

 

 

标签:元素,Java,UiSelector,UiObject,childPattern,UI,Uiautomator,UiCollection
来源: https://blog.csdn.net/ricky_yangrui/article/details/89435161

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有