I use Appium to Automate and Test the Mobile Apps. There will be many occasions where the App crashes because of a bug in it and then the Test fails. Test failures can be because of many reasons but failures because of an app crash should be identified and reported in the Test Report Properly. I want to know if there is any way we can detect an app crash in an Automated fashion.
Using Appium java-client, you could use the android driver method currentActivity() This tells you what activity is currently frontmost on the device. If the app has crashed then currentActivity won't return any activities from your app.
Javadoc here: http://appium.github.io/java-client/io/appium/java_client/android/AndroidDriver.html#currentActivity()
Example code:
String activity = driver.currentActivity();
if (!activity.equals("com.myapp.myactivity")){
log("App crashed!");
}
You could put this check inside a test watcher that gets called when there is a test failure. This way you can log more details and highlight potential crashes. If you're using jUnit, you could use http://junit.org/apidocs/org/junit/rules/TestWatcher.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With