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

滑动到某个对象

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

返回值API描述
booleanscrollIntoView(UiSelector selector)滑动到条件元素所在位置,并且尽量让其居于屏幕中央
booleanscrollIntoView(UiObject obj)滑动到对象所在位置,并且尽量让其居于屏幕中央
booleanscrollTextIntoView(String text)滑动到文本对象所在位置,并且尽量让其居于屏幕中央
booleanscrollDescriptionIntoView(String text)滑动到文本描述对象所在位置,并且尽量让其居于屏幕中央
booleanscrollToBeginning(int maxSwipes)自定义扫动次数,滑动到开始位置
booleanscrollToBeginning(int maxSwipes, int steps)自定义扫动次数与步长,滑动到开始位置
booleanscrollToEnd(int maxSwipes)自定义扫动次数,滑动到结束位置
booleanscrollToEnd(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

 

转载于:https://www.cnblogs.com/fsw-blog/p/4597818.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值