Issue
I'm testing an interaction when in app, user can swipe up to go to Google Play Store. But when that happens, Espresso can not execute rest of the test flow due to RuntimeException: Could not find RESUMED activity on main thread.
On the UI there's left arrow (<--) so user can tap on it to go back to previous app. How do I tell Espresso to do similar thing? Or force the app being tested to come to the foreground again?
Below is the RuntimeException for reference:
java.lang.RuntimeException: Could not find RESUMED activity on main thread
at com.snapchat.android.crema.Screenshotter.screenshotCurrentActivity(Screenshotter.java:49)
at com.snapchat.android.crema.Screenshotter$1.run(Screenshotter.java:33)
at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:2092)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
INSTRUMENTATION_RESULT: shortMsg=Process crashed.
INSTRUMENTATION_CODE: 0
Solution
Espresso cannot be used for a cross-app testing. Espresso is bound to your application process.
But there are ways of testing this interaction:
Catch the intent to go the play store with Espresso-Intents and return a stub response. This way, your test will be canned and will never leave your application. This is a recommended way of doing it as it tests this scenario in isolation without interacting with the external dependency that is out of your control.
Use UiAutomator that can act outside of the context of your application and click things there. Might be useful if you are interested in end-end testing, but with the tradeoff of being more fragile. You can find sample usage in this question: How to regain Access on a Activity after sending it to background
Answered By - Be_Negative
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.