uiautomator:UiDevice

上一篇 / 下一篇  2014-07-14 17:18:38 / 个人分类:android

UiDevice:提供关于设备的状态信息。你也可以使用这个类来模拟装置上的用户的行为,如按方向键或按菜单按钮

void clearLastTraversedText();  遍历从过去的ui事件中,清除文本(上一次的输入)clears the text from the last UI traversal event

String getLastTraversedText();

点击.拖拽.层级
boolean click(int x, int y)
boolean drag(int startX, int startY, int endX, int endY, int steps)
void dumpWindowHierarchy(String fileName); 用于调试转存当前窗口的布局层次结构,文件保存在/data/local/tmp

void setCompressedLayoutHeirarchy(boolean compressed); 启动或禁用布局层次压缩

获取信息:
String getCurrentActivityName();
String getCurrentPackageName();
int getDisplayHeight();
int getDisplayRotation();
Point getDisplaySizeDp();
int getDisplayWidth();
static UiDevice getInstance();
String getLastTraverseText();
String getProductName();

旋转:
void freezeRotation();
void unfreezeRotation();

boolean isNaturalOrientation(); 检查设备是否是在其自然旋转竖屏的位置上

void setOrientationLeft(); 通过禁用传感器,然后模拟设备向左转,并且固定位置
void setOrientationNatural();
void setOrientationRight();

锁屏与唤醒
void sleep();锁屏 模拟按电源键,如果屏幕已经是关闭的,则没有任何作用

void wakeUp();唤醒 模拟按电源键,如果屏幕是唤醒的,则没有任何作用

boolean isScreenOn(); 检查屏幕是否唤醒

等待
void waitForIdle(long timeout); 等待当前应用程序处于空闲状态
void waitForIdle();
boolean waitForWindowUpdate(String packageName, long timeout); 等待窗口内容更新事件的发生

监听器
void registerWatcher(String name, UiWatcher watcher)
void removeWatcher(String name);
void resetWatcherTriggers();
void runWatchers();

boolean hasAnyWatcherTriggered()
boolean hasWatcherTriggered(String watcherName)

按键事件(boolean)
pressBack()、pressDPadCenter()、pressDPadDown()、pressDPadUp()、pressDPadLeft()、pressDPadRight()、pressDelete()、pressEdit()、pressHome()、pressSearch()pressMenu()pressRecentApps()pressKeyCode(int keyCode, int metaState)、pressKeyCode(int keyCode)

截图
boolean takeScreenshot(File storePath);  把当前窗口截图并将其存储为png,默认1.0f的规模和90%质量,参数为file类型的文件路径

boolean takeScreenshot(File storePath, float scale, int quality);  把当前窗口截图为png格式图片,可以自动以缩放比例与图片质量

滑动
boolean swipe(Point[] segments, int segmentSteps); 在点阵列中滑动,5ms一步

boolean swipe(int startX, int startY, int endX, int endY, iint steps); 通过坐标滑动屏幕

通知栏.快速设置
boolean openNotification(); 打开通知栏

boolean openQuickSettings(); 打开快速设置







TAG:

 

评分:0

我来说两句

Open Toolbar