android uiautomator写一个崩溃的监听
本人在测试公司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;}});
}
更多相关文章
- Android(安卓)自定义方形验证码输入框,仿滴滴、小篮单车
- Android之控件保持在软键盘上面
- android 项目 R.java文件丢失?
- Android组件开发之ListView遇到的一个问题
- Android(安卓)Studio报错之Error:Execution failed for task ':a
- Android抓包工具使用与错误
- android错误之ListView设置setOnItemClickListener失效
- Android报No resource found that matches the given name问题的
- WebView滑动监听