Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect an app crash in android when running Automated Tests against them?

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.

like image 283
Sai Manoj Bandi Avatar asked Oct 20 '25 04:10

Sai Manoj Bandi


1 Answers

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

like image 189
Nico Avatar answered Oct 22 '25 03:10

Nico



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!