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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ricky_yangrui/article/details/89435161

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)

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

用法:

猜你喜欢

转载自blog.csdn.net/ricky_yangrui/article/details/89435161