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


    滑动到某个对象

    一、滑动到某个对象相关API

    返回值 API 描述
    boolean scrollIntoView(UiSelector selector) 滑动到条件元素所在位置,并且尽量让其居于屏幕中央
    boolean scrollIntoView(UiObject obj) 滑动到对象所在位置,并且尽量让其居于屏幕中央
    boolean scrollTextIntoView(String text) 滑动到文本对象所在位置,并且尽量让其居于屏幕中央
    boolean scrollDescriptionIntoView(String text) 滑动到文本描述对象所在位置,并且尽量让其居于屏幕中央
    boolean scrollToBeginning(int maxSwipes) 自定义扫动次数,滑动到开始位置
    boolean scrollToBeginning(int maxSwipes, int steps) 自定义扫动次数与步长,滑动到开始位置
    boolean scrollToEnd(int maxSwipes) 自定义扫动次数,滑动到结束位置
    boolean scrollToEnd(int maxSwipes, int steps) 自定义扫动次数与步长,滑动到结束位置

    说明:所有函数都是先在当前界面查找是否有要找的对象,没找到则先向上滑动指定的扫动次数,然后再向下滑动的同时查找有没有这个对象,但也仅向下滑动指定的扫动次数,找不到则会报错。 

    二、相关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="testScrollIntoView";
            androidId="1";
            new UiAutomatorHelper(jarName, testClass, testName, androidId);
    
        }
        
        public void testScrollIntoView() throws UiObjectNotFoundException{
            UiDevice.getInstance().pressHome();
            sleep(1000);
            
            UiObject people=new UiObject(new UiSelector().text("People"));
            people.click();
            sleep(2000);
            
            UiScrollable scroll=new UiScrollable(new UiSelector().className("android.widget.ListView"));
            
            scroll.scrollToBeginning(50);
            sleep(3000);
            
            UiSelector testview=new UiSelector().text("test");
            scroll.scrollIntoView(testview);
            sleep(3000);
            
            scroll.scrollToBeginning(50, 5);
            sleep(3000);
            
            UiObject test=new UiObject(testview);
            scroll.scrollIntoView(test);
            sleep(3000);
            
            scroll.scrollToEnd(50);
            sleep(3000);
            
            scroll.scrollTextIntoView("test");
            sleep(3000);
            
            scroll.scrollToEnd(50,5);
            sleep(3000);
            
            scroll.scrollDescriptionIntoView("Quick contact for test");
            
        }
        
    }
    Demo.java
  • 相关阅读:
    Eclipse本地创建新的GIT分支,并推送至远程Git分支
    将持久态数据转化为游离态数据代码实现
    Java根据当前日期获得昨天的当前日期代码实现
    @RequestMapping和@GetMapping区别
    炫酷的banner.txt
    小程序colorUI框架初步使用教程
    Java Spring boot element ui activiti前后端分离,流程审批,权限管理框架
    Activiti (一)
    CSS Clip 裁剪
    @SpringBootApplication的使用
  • 原文地址:https://www.cnblogs.com/fsw-blog/p/4597818.html
Copyright © 2020-2023  润新知