Android UiAutomator:UiWatcher的使用

UiAutomator 是一个黑盒的自动化测试工具,UI界面被异常打断就会破坏脚本的正常运行。UiWatcher 可以处理某些可预知的打断场景。
这里例举来电打断场景处理。

代码

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值