UiScrollable
作用:滚动控件, 当目标控件存在于屏幕之外时使用
描述: 继承于UiCollection, 使用该控件描述界面滑动列表, 当目标控件存在于可见范围之外时, 可以使用getChild系列方法来
获取, UiScrollable会自动完成滑动操作以遍历列表里的所有元素。
获取列表的字元素
返回值 | API | 备注 |
---|
UiObject | getChildByDescription(UiSelector childPattern, String text, boolean allowScrollSearch) | 是否允许滚动查找获取局别UiSelector条件元素集合后再以文本描述条件查找对象 |
UiObject | getChildByDescription(UiSelector childPattern, String text) | 默认滚动获取具备UiSelector条件的元素集合后再以文件描述条件查找对象 |
UiObject | getChildByInstance(UiSelector childPattern, int instance) | 获取具备UISelector条件的子集,再从子集中按照实例筛选想要的元素,不滚动 |
UiObject | getChildByText(UiSelector childPattern, String text, boolean allowScrollSearch) | 是否允许滚动获取具备条件的元素集合再以文本的条件查找对象 |
UIObject | getChildByText(UiSelector childPattern, String Text) | 默认滚动获取具备UISelector条件元素集合后再以文本条件的查找对象 |
@Test
public void testDemo() throws UiObjectNotFoundException {
UiScrollable scroll = new UiScrollable(new UiSelector().className(""));
UiObject test = scroll.getChildByText(new UiSelector().className(""), "123", true);
test.click();
}
例子:封装一个长列表查询。
//封装一个列表查询
public void settingsListItem(String item) throws UiObjectNotFoundException {
if (mDevice.hasObject(By.textContains(item))) {
find(By.textContains(item)).clickAndWait(Until.newWindow(), 3000);
} else {
UiScrollable findItem = new UiScrollable(new UiSelector().className("android.support.v7.widget.RecyclerView"));
findItem.scrollTextIntoView(item);
find(By.textContains(item)).clickAndWait(Until.newWindow(), 3000);
}
}
获取与设置最大滚动次数量值
返回值 | API | 备注 |
---|
int | getMaxSearchSwipes() | 获取执行搜索滚动过程中的最大滚动次数,默认数量为30 |
UiScrollable | setMaxSearchSwipe(int swipes) | 设置最大可扫动次数 |
@Test
public void testDemo() throws UiObjectNotFoundException {
UiScrollable scroll = new UiScrollable(new UiSelector().className(""));
scroll.setMaxSearchSwipes(3);
scroll.getMaxSearchSwipes();
}
滑动区域校准常量设置与获取
校准常量:滑动操作坐标时的偏移量,用来取偏移的比例
返回值 | API | 备注 |
---|
double | getSwipDeadZonePercentage() | 默认常量的值为0.1, 10% |
UiScrollable | setSwipDeadPercentage(double swipeDeadZonePercentage) | 设置一个部件的大小,在滑动时候视为无接触区的百分比 |
@Test
public void testDemo() throws UiObjectNotFoundException {
UiScrollable scroll = new UiScrollable(new UiSelector().className(""));
double test = scroll.getSwipeDeadZonePercentage();
System.out.println("滑动区域的百分比" +test);
scroll.setSwipeDeadZonePercentage(0.15);
}
向前与向后滚动
返回值 | API | 备注 |
---|
boolean | scrollBackward(int steps) | 自定义步长向后滚动 |
boolean | scrollBackward() | 默认步长为55向后滑动 |
boolean | scrollForward | 默认步长为55向前滑动 |
boolean | scrollBackward(int steps) | 自定义步长向前滚动 |
@Test
public void testDemo() throws UiObjectNotFoundException {
UiScrollable scroll = new UiScrollable(new UiSelector().className(""));
scroll.setSwipeDeadZonePercentage(0.1);
scroll.scrollForward(5000);
scroll.scrollBackward();
}
滚动到某个对象
返回值 | API | 备注 |
---|
Boolean | scrolLIntoview(UiSelector selector) | 滚动到条件元素所在位置,并且尽量让其居于屏幕中央 |
Boolean | scrollIntoview (uiobject obj) | 滚动到文本对象所在位置,并且尽量让居于屏幕中央 |
Boolean | scrollDescriptionIntoView(String.text) | 滚动到描述所在位置,并且尽量让它居于屏幕中央 |
Boolean | scrolLToBeginning(int maxSwipes) | 滚动到开始位置 |
Boolean | scrolLToBeginning(int maxSwipes, int |
steps) | 自定义扫动次数与步长滚动到开始位置 |
Boolean | scrolLToEnd(int maxSwipes, int steps) | 自定义扫动次数与步长滚动到结束位置 |
Boolean | scrolLToEnd(int maxSwipes) | 自定义扫动次数滚动到结束位置 |
public void testscrollIntoView() throws UiobjectNotFoundExcept
Uiscrollable scroll=new Uiscrollable(new UiSelector().clasUiSelector selector=new UiSelector().text ("白");
Uiobject object=new Uiobject(selector);
//scroll.scrollIntoView(selector);
//scroll.scrollIntoView(object);
//scroll.scrollTextIntoView ("白");
scroll.scrollDescriptionIntoView("照片");
设置滚动方向
返回值 | API | 备注 |
---|
uiscrollable | setAsHorizontalList() | 设置滚动方向设置为水平滚动 |
uiscrollable | setAsVerticalList() | 设置滚动方向设置为纵向滚动 |
public void testVertical() throws UiobjectNotFoundException{
Uiscrollable scroll=new Uiscrollabie(new UiSelector().className("");
scroll.setAsHorizontalList();
scroll.setAsVerticalList();
}