Android UiAutomator UiScrollable类

引用:极客学院 Android UiAutomator UiScrollable
一. UiScrollable类说明
参考官方文档:UiScrollable
中国大陆正常是无法访问的,可参考Android官网访问设置:通过Host设置访问Android官网


二. 环境说明
IDE: Android Studio 2.3.1
JAVA: JDK1.8.0_121
测试框架:Junit4
Android:Android SDK


三. 快速滚动
1. 滚动相关概念
1) 步长:控制扫动速度
2) 扫动次数
实例:

// flingBackward(), flingForward(),
//flingToBeginning(int maxSwipes), flingToEnd(int maxSwipes)
@Test
public void testFling throws UiObjectNotFoundException {

        UiScrollable scroll=new UiScrollable(new UiSelector().className("android.widget.ListView"));

        //scroll.flingBackward();
        //scroll.flingForward();
        //scroll.flingToBegin(20);
        //scroll.flingToEnd(20);
    }

四、获取列表子元素

返回值API
UiObjectgetChildByDescription(UiSelector childPattern, String text)
UiObjectgetChildByDescription(UiSelector childPattern, String text, boolean allowScrollSearch)
UiObjectgetChildByInstance(UiSelector childPattern, int instance)
UiObjectgetChildByText(UiSelector childPattern, String text, boolean allowScrollSearch)
UiObjectgetChildByText(UiSelector childPattern, String text)

实例:

@Test
    public void testScroll() throws RemoteException, UiObjectNotFoundException {

        UiScrollable scrollable=new UiScrollable(new UiSelector().className("android.widget.ListView"));
        // getChildByText
        UiObject object=scrollable.getChildByText(new UiSelector().className("android.widget.TextView"), "Views", true);
        object.click();
        // getChildByInstance
        scrollable.getChildByInstance(new UiSelector().className("android.widget.TextView"), 3).click();
    }

五. 获取与设置最大滚动次数常量值

返回值API
intgetMaxSearchSwipes()
UiScrollablesetMaxSearchSwipes(int swipes)

实例:

@Test
    public void testSwipCount() throws UiObjectNotFoundException {
        UiScrollable scroll=new UiScrollable(new UiSelector().className("android.widget.TextView"));
        UiObject textView=new UiObject(new UiSelector().text("Views"));
        scroll.scrollIntoView(textView);
        scroll.setMaxSearchSwipes(3);
        textView.click();
        System.out.println("maxswipes: "+scroll.getMaxSearchSwipes());
    }

六. 滑动区域校准常量设置与获取

返回值API
doublegetSwipeDeadZonePercentage()
UiScrollablesetSwipeDeadZonePercentage(double swipeDeadZonePercentage)

实例:

@Test
    public void testDeadZoon() throws UiObjectNotFoundException, RemoteException {
        UiScrollable scroll=new UiScrollable(new UiSelector().className("android.widget.ListView"));
        scroll.setSwipeDeadZonePercentage(0.1);
        scroll.scrollForward(2);
    }

七. 向前与向后滚动

返回值API
booleanscrollBackward(int steps)
booleanscrollBackward()
booleanscrollForward(int steps)
booleanscrollForward()

八. 滚动到某个对象

返回值API
booleanscrollIntoView(UiSelector selector)
booleanscrollIntoView(UiObject obj)
booleanscrollTextIntoView(String text)
booleanscrollToBeginning(int maxSwipes)
booleanscrollToBeginning(int maxSwipes, int steps)
booleanscrollToEnd(int maxSwipes)
booleanscrollToEnd(int maxSwipes, int steps)

实例:

@Test
    public void testScrollIntoView() throws UiObjectNotFoundException {
        UiScrollable scroll=new UiScrollable(new UiSelector().className("android.widget.ListView"));
        UiSelector selector=new UiSelector().text("Lists");
        scroll.setMaxSearchSwipes(1);
        scroll.scrollIntoView(selector);
    }

九. 设置滚动方向

返回值API
UiScrollablesetAsHorizontalList()
UiScrollablesetAsVerticalList()

实例:

@Test
    public void testScrollIntoView() throws UiObjectNotFoundException {
        UiScrollable scroll=new UiScrollable(new UiSelector().className("android.widget.ListView"));
        scroll.setAsHorizontalList();
        scroll.scrollForward();
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值