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

设置滚动方向

一、设置滚动方向相关API

返回值 API 描述
UiScrollable setAsHorizontalList 设置滚动方向为水平滚动
UiScrollable setAsVerticalList 设置滚动反向为纵向滚动

 

 

 

 

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

    }
    
    public void testSetAs() 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.support.v4.view.ViewPager"));
        
        //设置为水平滚动
        scroll.setAsHorizontalList();
        scroll.scrollBackward();
        sleep(2000);
        scroll.scrollForward();
        sleep(2000);
        
        //设置为纵向滚动
        scroll.setAsVerticalList();
        scroll.scrollForward();
    }
    
}
Demo.java

 

posted on 2015-06-24 16:54  发卡  阅读(533)  评论(0编辑  收藏  举报