原文:https://www.jianshu.com/p/93a41f948e1a
适合全局处理,意外弹出的对话框之类的东西。
public class MyWatcher implements UiWatcher { private UiDevice mDevice; public MyWatcher(UiDevice device){ mDevice = device; } @Override public boolean checkForCondition() {
if(mDevice.hasObject(By.text("删除安装包"))){ mDevice.pressBack();
return true; } return false; } }
完成定以后,在脚本的setUp里注册自己的watcher,当控件查找失败时就会自动调用watcher了。
myWatcher = new MyWatcher(mDevice); mDevice.registerWatcher("testwatcher",myWatcher);
|