您的位置:首页 > 产品设计 > UI/UE

Android 自动化测试经验 - UiScrollable

2013-01-24 09:17 281 查看
UiScrollable is a
UiCollection
and provides support for searching for items in a scrollable user interface (UI) elements. This class can be used with horizontally or vertically scrollable controls.

UiScrollable是一个UiCollection(这东西还没搞懂),我们可以使用它,在可滑动的页面(水平滑动或上下滑动都可以)上查找我们想要的控件(item)。

例1:下面的这个scrollClickObject方法就是使用UiScrollable,来自动选择我们想要点击的那个控件。

public void scrollClickObject(String targetClassName,String targetName) throws UiObjectNotFoundException {
UiScrollable collectionObject = new UiScrollable(new UiSelector().scrollable(true));
if(collectionObject.exists()) {
UiObject scrollableObject = collectionObject.getChildByText(new UiSelector().className(targetClassName), targetName);
scrollableObject.clickAndWaitForNewWindow();
} else {
UiObject targetObject = new UiObject(new UiSelector().className(targetClassName).text(targetName));
targetObject.clickAndWaitForNewWindow();
}
}


首先定义一个UiScrollable对象,识别这个对象的唯一条件就是,屏幕上有可滑动的控件。(这里有一个问题,就是如果屏幕上同时存在2个可滑动的控件,就会报错了)

然后我们判断这个可滑动对象是否存在

存在,则使用getChildByText方法,获取我们想要点击的那个控件,然后点击它

不存在,则说明页面不可滑动,也就是所有控件均已显示在界面上。那我们就可以直接使用UiObject获取控件并操作它。

例2:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: