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

快速滑动

一、快速滑动相关概念

1、步长:从一点滑动到另一点所用的时间

2、扫动次数:例如列表,要滑动多少次才能到底部,这个滑动次数就是扫动次数

二、相关API

返回值 API 描述
boolean flingBackward() 以步长为5快速向后滑动
boolean filingForward() 以步长为5快速向前滑动
boolean flingToBeginning(int maxSwipes) 自定义扫动次数以步长为5快速滑动到起始
boolean flingToEnd(int maxSwipes) 自定义扫描次数以步长为5快速滑动到末尾

 

 

 

 

 

 

三、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="testFling";
        androidId="1";
        new UiAutomatorHelper(jarName, testClass, testName, androidId);

    }
    
    public void testFling() throws UiObjectNotFoundException{
        UiDevice.getInstance().pressHome();
        sleep(2000);
        
        UiSelector l=new UiSelector().text("People");
        UiObject p=new UiObject(l);
        p.click();
        sleep(2000);
        UiScrollable scroll=new UiScrollable(new UiSelector().className("android.widget.ListView"));
        scroll.flingForward();
        sleep(3000);
        scroll.flingBackward();
        sleep(3000);
        scroll.flingToEnd(5);
        sleep(3000);
        scroll.flingToBeginning(5);
        
    }

}
Demo.java

 

posted on 2015-06-23 17:05  发卡  阅读(1027)  评论(0编辑  收藏  举报