标签:
一、概念介绍:
1)拖拽:将组建从一个坐标移动到另一个坐标
2)移动:从一二坐标点移动到另一个坐标点
3)步长:从一点滑动到另一点使用的时间
二、拖拽与滑动的相关API:
返回值 | 方法名 | 描述 |
boolean | drag(int startX, int startY, int endX, int endY, int steps) | 拖动对象从一个坐标拖动到另一个坐标 |
boolean | swipe(Point[] segments, int segmentSteps) | 再点阵列中滑动,5ms一步 |
boolean | swipe(int startX, int startY, int endX, int endY, int steps) | 通过坐标滑动屏幕 |
三、API应用举例:
package com.uiautomatortest; import android.graphics.Point; import android.os.Bundle; import android.os.RemoteException; import android.view.KeyEvent; import com.android.uiautomator.core.UiDevice; import com.android.uiautomator.testrunner.UiAutomatorTestCase; public class Test extends UiAutomatorTestCase { public void testDragAndSwipe(){ //[64,577][128,640] int startX, startY, endX, endY, steps; startX=(128-64)/2+64; startY=(640-577)/2+577; endX=startX; endY=startY-200; steps=100; UiDevice.getInstance().drag(startX, startY, endX, endY, steps); Point p1=new Point(); Point p2=new Point(); Point p3=new Point(); Point p4=new Point(); p1.x=78;p1.y=30; p2.x=235;p2.y=309; p3.x=224;p3.y=414; p4.x=76;p4.y=409; Point[] ps={p1,p2,p3,p4,p1}; UiDevice.getInstance().swipe(ps, 50); //(278,374),(69,373) int startX=278; int startY=374; int endX=69; int endY=373; int steps=100; UiDevice.getInstance().swipe(startX, startY, endX, endY, steps); } }
Android无线测试之—UiAutomator UiDevice API介绍四
标签:
原文地址:http://www.cnblogs.com/fsw-blog/p/4546150.html