zoukankan      html  css  js  c++  java
  • Android无线测试之—UiAutomator UiObject API介绍三

    拖拽与滑动

    一、拖拽与滑动的示意图

    二、拖拽与滑动相关的API

    返回值 API 描述
    boolean dragTo(UiObject destObj, int setps) 拖拽对象到另一个对象位置上,步长可设置拖动的速度
    boolean dragTo(int destX, int destY, int steps) 拖拽对象到屏幕某个坐标位置上,步长可设置拖动速度
    boolean swipeDown(int steps) 拖动对象往下滑动
    boolean swipeLeft(int steps) 拖拽对象往左滑动
    boolean swipeRight(int steps) 拖拽对象往右滑动
    boolean swipeUp(int steps) 拖拽对象往上滑动
    package com.test.uiobject;
    
    import com.android.uiautomator.core.UiDevice;
    import com.android.uiautomator.core.UiObject;
    import com.android.uiautomator.core.UiObjectNotFoundException;
    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="demo";
            testClass="com.test.uiobject.Demo";
            testName="testSwipe";
            androidId="1";
            new UiAutomatorHelper(jarName,testClass,testName,androidId);
    
        }
        
        public void testDragTo() throws UiObjectNotFoundException{
            UiDevice.getInstance().pressHome();
            sleep(2000);
            
            UiObject people=new UiObject(new UiSelector().text("People"));
            UiObject camera=new UiObject(new UiSelector().text("Camera"));
            people.dragTo(camera, 50);
            
            UiObject preview=new UiObject(new UiSelector().resourceId("com.android.launcher:id/preview_background"));
            preview.clickAndWaitForNewWindow();
            
            UiObject insidePeople=new UiObject(new UiSelector().text("People"));
            insidePeople.dragTo(94, 603, 50);
        }
        
        public void testSwipe() throws UiObjectNotFoundException{
            UiObject camera=new UiObject(new UiSelector().text("Camera"));
            camera.swipeDown(50);
            sleep(2000);
            camera.swipeLeft(50);
            sleep(2000);
            camera.swipeRight(50);
            sleep(2000);
            camera.swipeUp(50);
        }
    
    }
    Demo.java
  • 相关阅读:
    推荐大家使用的CSS书写规范、顺序
    只能输入数字的文本框
    js和jQuery 获取屏幕高度、宽度
    jquery插件开发规范
    ie下使用firebug
    equals和==的使用
    引用数据类型的赋值
    数组工具Arrays的基本使用
    冒泡排序
    使用数组对杨辉三角练习
  • 原文地址:https://www.cnblogs.com/fsw-blog/p/4567272.html
Copyright © 2011-2022 走看看