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,uiautomator)