本人在测试公司app的时候,偶尔会碰到,用着用着崩溃的现在,程序会报错,还会有错误详情,今天看了看页面,写了一个崩溃的监听,感觉还不错,分享出来,如果错误,烦请指正。

getUiDevice().registerWatcher("error", new UiWatcher() {//崩溃监听
UiObject reboot = new UiObject(new UiSelector().text("错误详情"));
UiObject error =  new UiObject(new UiSelector().text("重新启动"));
@Override
public boolean checkForCondition() {
if(reboot.exists() && error.exists()){
System.out.println("this is serious error");
try {
error.clickAndWaitForNewWindow();
} catch (UiObjectNotFoundException e) {
e.printStackTrace();
}
UiObject details = new UiObject(new UiSelector().text("Error details"));
UiObject copy = new UiObject(new UiSelector().text("Copy to clipboard"));
if (details.exists() && copy.exists()) {
try {
copy.clickAndWaitForNewWindow();
} catch (UiObjectNotFoundException e) {
e.printStackTrace();
}
UiObject detailstext = new UiObject(new UiSelector().resourceId("android:id/message").className("android.widget.TextView"));
try {
System.out.println(detailstext.getText());
} catch (UiObjectNotFoundException e) {
e.printStackTrace();}
}
System.out.println("copy successfully !");
return true;}
System.out.println("copy failed");
return false;}});

    } 

更多相关文章

  1. Android(安卓)自定义方形验证码输入框,仿滴滴、小篮单车
  2. Android之控件保持在软键盘上面
  3. android 项目 R.java文件丢失?
  4. Android组件开发之ListView遇到的一个问题
  5. Android(安卓)Studio报错之Error:Execution failed for task ':a
  6. Android抓包工具使用与错误
  7. android错误之ListView设置setOnItemClickListener失效
  8. Android报No resource found that matches the given name问题的
  9. WebView滑动监听

随机推荐

  1. jquery mobile开发中常见的问题
  2. bootstrap,模态对话框,shown.bs.modal事件
  3. 如何将一个div中的a标签放在另一个div的a
  4. postman 发送json请求
  5. jquery.d。ts编译失败:TsLint:超过最大行
  6. 使用hibernate和vraptor通过POST插入带有
  7. Jquery活不在IE中工作
  8. 我做的第一个JQuery图片切换,希望大家多多
  9. window.open在Safari中的问题
  10. 登陆页面有延迟然后自动向下滚动