Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not return back with Espresso.pressBack() after open a PDF

I am trying to test my app with Espresso.

I have a problem: in one use case, i need to open a PDF for reading "User conditions" and i can not return back from this point with Espresso.pressBack(), always i have the error below:

android.support.test.espresso.NoActivityResumedException: No activities in stage RESUMED. Did you t to launch the activity. (test.getActivity() or similar)?
 at dalvik.system.VMStack.getThreadStackTrace(Native Method)
 at java.lang.Thread.getStackTrace(Thread.java:1538)
 at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError (DefaultFailureHandler.java:88)
 at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:51)
 at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
 at android.support.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:173)
 at android.support.test.espresso.ViewInteraction.perform(ViewInteraction.java:114)
 at android.support.test.espresso.Espresso.pressBack(Espresso.java:220)

Any suggested solution ?

like image 773
Mohamed Ali Benmansour Avatar asked Jan 27 '26 05:01

Mohamed Ali Benmansour


1 Answers

Just add:

dependencies {
  ...
  androidTestImplementation('androidx.test.uiautomator:uiautomator:$uiAutomatorVersion')
}

And then simply:

val device = UiDevice.getInstance(getInstrumentation())
device.pressBack()

This should be included in espresso I believe, no sense to have it as separate thing.

like image 62
Renetik Avatar answered Jan 28 '26 20:01

Renetik