标签:
UiDevice
类描述:
UiDevice用于访问有关设备的状态信息,你可以使用该类来模拟设备上的用户行为,例如d-pad键操作或者Home键和menu键
方法描述:
按键使用
click(int x,int y):boolean – UiDevice
//单击用户指定的坐标
pressBack():boolean-UiDevice
//模拟Back键
pressDelete():boolean-UiDevice
//模拟Delete键
pressDpadCenter():boolean-UiDevice
//模拟Center键
pressDpadDown():boolean-UiDevice
//模拟Down键
pressDpadLeft():boolean-UiDevice
//模拟左键
pressDpadRight():boolean-UiDevice
//模拟右键
pressDpadUp():boolean-UiDevice
//模拟UP键
pressEnter():boolean-UiDevice
//模拟Enter键
pressHome():boolean-UiDevice
//模拟HOME键
pressKeyCode(int keyCode):boolean-UiDevice
//使用keyCode模拟键盘按键
pressKeyCode(int keyCode,int metaState):boolean-UiDevice
//模拟按键代码,metaState=shift=1
pressMenu():boolean-UiDevice
//MENU键
pressRecentApps():boolean-UiDevice
//按最近应用程序按键
pressSearch():boolean-UiDevice
//模拟搜索键
拖拽与滑动
drag(int startX,int startY,int endX,int endY,int steps):boolean – UiDevice
//将一个坐标拖拽另一个坐标
swipe(Point[] segments,int segmentSteps):boolean-UiDevice
//点阵列中滑动,5ms为一步
//segments:Point[]点阵列,可多个点;segmentSteps:滑动步长
swipe (int startX,int startY,int endX,int endY,int steps):boolean – UiDevice
//滑动屏幕
旋转屏幕
freezeRotation():void – UiDevice
//禁用传感器和冻结当前旋转状态的设备旋转
getDisplayRotation():int – UiDevice
//返回当前的旋转状态,0,1,2,3分表代表0,90,180,270
serOrientationLeft():void-UiDevice
//禁用传感器,模拟屏幕设备左转,并且固定位置
setOrientationNatural():void-UiDevice
//禁用传感器,模拟屏幕转到其自然默认方向,并固定位置
setOrientationRight():void-UiDevice
//固定传感器,模拟屏幕设备右转,并且固定位置
unfreezeRotation():void-UiDevice
//重新启用传感器和允许物理旋转
isNaturalOrientation(): boolean-UiDevice
//检查装置是否在自然旋转竖屏位置上
灭屏与唤醒屏幕
wakeup():void-UiDevice
//该方法模拟按电源键,如果屏幕已唤醒则无任何作用
isScreenOn():boolean-UiDevice
//检查屏幕是否唤醒
sleep():void-UiDevice
//锁屏(若屏幕关闭则无作用)
截图与等待空闲
takeScreenshot(File storePath):boolean– UiDevice
//将当前窗口截屏并存储为png默认1.0f的规模(原尺寸)和90%的质量,storePath为文件路径
takeScreenshot(File storePath,float scale,int quality):boolean– UiDevice
//将当前窗截图为png格式图片,可自定义缩放比例和质量
//scale:缩放比例,1.0为原图;quality:图片压缩质量,范围1-100
wait():void-Object
//一直处于睡眠状态,直到调用notify或者notifyAll
notify():void-Object
//唤醒正在等待该对象的线程
notifyAll():void-Object
//唤起所有正在等待该对象的线程
wait(long timeout):void-Object
//等待**毫秒被唤醒
wait(long timeout,int nanos):void-Object
//等待**毫秒**纳秒结束时被唤醒
waitForIdle():void-UiDevice
//等待当前应用程序处于空闲状态,默认10S
waitForIdle(long timeout):void-UiDevice
//自定义超时等待当前窗口处于空闲状态
waitForWindowUpdate(String packageName,long timeout):boolean-UiDevice
//等待窗口内容更新的发生
获取包名、设备名
getCurrentPackageName():String – UiDevice
//获得当前包名:检索最新的可访问性事件的包名
getProductName():String – UiDevice
//获得产品设备名
开启通知栏,打开快速设置
openNotification():boolean-UiDevice
//打开通知栏
openQuickSettinghs():boolean-UiDevice
//打开快速设置
获取布局文件
getDisplayHeight():int – UiDevice
//获取显示高度,以像素为单位
getDisplaySizeDp():Point – UiDevice
//返回显示尺寸(以dp为单位),返回的尺寸适应每个屏幕的旋转
getDisplayWidth():int – UiDevice
//获得显示宽度,以像素为单位
dumpWindowHierachy(String fileName):void – UiDevice
//帮助方法,用于调试转储当前窗口的布局层次,文件保存于/data/local/tmp
setCompressedLayoutHeirarchy(boolean compressed):void-UiDevice
//启用或禁用布局层次压缩
监听器
registerWatcher(String name,UiWatcher watcher):void-UiDevice
//注册UIWatcher并自动运行,当测试框架无法找到一个匹配时使用UISelector
removeWatcher(String name):void-UiDevice
//移除之前注册的UIWatcher
resetWatcherTriggers():void-UiDevice
//重置已经触发的UIWatcher
runWatcher():void-UiDevice
//强制运行所有的UIWatcher.
hasAnyWatcherTriggered():boolean-UiDevice
//检查是否有UIWatcher触发
hasWatcherTriggered(String watcherName):boolean-UiDevice
//检查某个特定的监听器是否触发
其它
clearLastTraversedText():void – UiDevice
//遍历从过去的UI事件中,清除文本(上一次的输入)
getCurrentActivityName():String – UiDevice
//此方法过时,返回结果认为不可靠
getLastTraversedText():String – UiDevice
//检索收到的最后一次遍历事件的文本
getInstance():Uidevice-UiDevice
//检索单个UIdevice实例
标签:
原文地址:http://www.cnblogs.com/wonderful0714/p/4580029.html