How to detect App crash in reality

I want to notify my test as failed when the App is crashed.
How to detect if the app is crashed? [because it can happen @random times @ random places]
So that the capture screenshot can be called and sent in test reports.
Right now the test just fails because it doesn’t find the appropriate element on page due to App crash [‘Unfortunately stopped’ popup in Android] , but that can happen due to some other reason too.

Does Appium runs a listener or something which tracks if the app is crashed.

1 Like

You could use something like HockeyApp

Thanks Mathew!
but we already have localitycs which reports crashes on live app.
but my requirement is while the automation is running that time I want to capture [atleast a screenshot]-> so that I know that due to crash my script failed else, its like wondering why this element was timedout/not found. [so the sole purpose is not to report crashes but it can be a byproduct in functional testing ]

You can capture a screenshot on test failure but i don’t think it would help to get a screenshot at app crash. What would this serve in this context?
I believe you would get a main screen on iOS and an ‘unfortunately’ message in android?

I am not sure about iOS but on Android i used to get live logcat output equal and higher to ERROR level than check them if there is anything FATAL, if there is report it to certain places. (This being done in test scripts, by a helper method)

You can access the crashlog on iOS and the logcat log on Android via the selenium logging API.

1 Like

You could also use the “get current activity” implementation in your client to assert the view is what you expect.

@p00j4 Did you find a solution to this? I’ve thought about this too but haven’t start researching a great method to trap a crash.

I don’t believe the simulator will exit to the SpringBoard (iOS home screen) because XCode won’t allow an app crash - in stead the app will freeze which will force a NoSuchElementException and fail the test.

I would think you could asynchronously search for exceptions within the iOS log for crashes and raise a custom exception.

1 Like