• Android无线测试之—UiAutomator UiScrollable API介绍四


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

    一、获取与设置最大滚动次数常量值相关API

    返回值 API 描述
    int getMaxSearchSwipes() 获取执行搜索滑动过程中的最大滑动次数,默认最大滚动次数为30
    UiScrollable setMaxSearchSwipes(int swipes) 设置最大可滑动次数

    二、API应用举例

    package com.testuiselector;
    
    import com.android.uiautomator.core.UiDevice;
    import com.android.uiautomator.core.UiObject;
    import com.android.uiautomator.core.UiObjectNotFoundException;
    import com.android.uiautomator.core.UiScrollable;
    import com.android.uiautomator.core.UiSelector;
    import com.android.uiautomator.testrunner.UiAutomatorTestCase;
    
    public class Demo extends UiAutomatorTestCase {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            
            String jarName, testClass, testName, androidId;
            jarName="demo2";
            testClass="com.testuiselector.Demo";
            testName="testSearchSwipes";
            androidId="1";
            new UiAutomatorHelper(jarName, testClass, testName, androidId);
    
        }
        
        public void testSearchSwipes() throws UiObjectNotFoundException{
            UiDevice.getInstance().pressHome();
            sleep(1000);
            
            UiObject people=new UiObject(new UiSelector().text("People"));
            people.clickAndWaitForNewWindow();
            
            UiScrollable scroll=new UiScrollable(new UiSelector().className("android.widget.ListView"));
            
            //最大滑动次数为默认30次,成功找到联系人X
            UiObject textview=new UiObject(new UiSelector().text("X"));
            scroll.scrollIntoView(textview);
            textview.click();
            System.out.println("最大滑动次数="+scroll.getMaxSearchSwipes());
            UiDevice.getInstance().pressBack();
            
            //设置虽大滑动此洞为3次,导致到不到联系人A,因此报错
            UiObject textview1=new UiObject(new UiSelector().text("A"));
            scroll.setMaxSearchSwipes(3);
            scroll.scrollIntoView(textview1);
            textview.click();
            
        }
    }
    Demo.jaa
  • 相关阅读:
    http从发出请求到接收响应的旅行
    git(二)github的使用入门及搜索技巧
    git(一) 基础
    获取基于Internet Explorer_Server的聊天窗口内容
    主机字节与网络字节的转换
    SQL Server存储过程中防止线程重入处理方式
    利用NVelocity 模版生成文本文件
    C# async await 学习笔记2
    C# async await 学习笔记1
    imx6 工具链下载地址
  • 原文地址:https://www.cnblogs.com/fsw-blog/p/4597265.html
Copyright © 2020-2023  润新知