码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-06-24 18:06:17      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

滑动到某个对象

一、滑动到某个对象相关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

 

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

标签:

原文地址:http://www.cnblogs.com/fsw-blog/p/4597818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!