Android UiAutomator:UiWatcher的使用
2016-06-21 12:18
806 查看
UiAutomator 是一个黑盒的自动化测试工具,UI界面被异常打断就会破坏脚本的正常运行。UiWatcher 可以处理某些可预知的打断场景。
这里例举来电打断场景处理。
代码
代码中处理来电打断的场景关闭来电的动作。
当UiSelector无法找到相关Object后,由testing framework启动UiWatcher中的checkForCondition方法。
相关资料
public abstract boolean checkForCondition ()
The testing framework calls this handler method automatically when the framework is unable to find a match using the UiSelector. When a match is not found after a predetermined time has elapsed, the framework calls the checkForCondition() method of all registered watchers on the device. You can use this method to handle known blocking issues that are preventing the test from proceeding. For example, you can check if a dialog appeared that is blocking the the test, then close the dialog or perform some other appropriate action to allow the test to continue.
Returns
true to indicate a matched condition, or false if no matching condition is found
这里例举来电打断场景处理。
代码
UiWatcher watcher = new UiWatcher(){ public boolean checkForCondition(){ UiObject Incall = new UiObject(new UiSelector().resourceId("com.android.incallui:id/answerFragment")); if(Incall.exists()) { try{ Incall.swapLeft(20); return true; }catch(Exception e){ e.printStackTrace(); return false; } } else return false; } }; UiDevice.getInstance().registerWatcher("phone",watcher); //注册UiWatcher
代码中处理来电打断的场景关闭来电的动作。
当UiSelector无法找到相关Object后,由testing framework启动UiWatcher中的checkForCondition方法。
相关资料
public abstract boolean checkForCondition ()
The testing framework calls this handler method automatically when the framework is unable to find a match using the UiSelector. When a match is not found after a predetermined time has elapsed, the framework calls the checkForCondition() method of all registered watchers on the device. You can use this method to handle known blocking issues that are preventing the test from proceeding. For example, you can check if a dialog appeared that is blocking the the test, then close the dialog or perform some other appropriate action to allow the test to continue.
Returns
true to indicate a matched condition, or false if no matching condition is found
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories