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

向前与向后滚动API

一、向前与向后滚动相关API

返回值 API 描述
boolean scrollBackward(int steps) 自动以步长向后滑动
boolean scrollBackward() 以默认步长55向后滑动
boolean scrollForward() 以默认步长55向前滑动
boolean scrollForward(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="testScrollBackwardAndForward";
        androidId="1";
        new UiAutomatorHelper(jarName, testClass, testName, androidId);

    }

    public void testScrollBackwardAndForward() 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"));
        
        //向前滑动,默认步长55
        scroll.scrollForward();
        sleep(3000);
        
        //向前滑动,指定步长为5
        scroll.scrollForward(5);
        sleep(3000);
        
        //向后滑动,默认步长为5
        scroll.scrollBackward();
        sleep(3000);
        
        //向后滑动,指定步长为5000
        scroll.scrollBackward(5000);
    }
}
Demo.java


 

 

posted on 2015-06-24 15:12  发卡  阅读(496)  评论(0编辑  收藏  举报