I am using Espresso for UI testing. I wanna test a feature that Intent the app to the google maps app and come back to the same activity. The Intent is done successfully and the google maps is opened but i dont have control over the maps app and Espresso.pressBack();
is not working. Is there a way to press back button using espresso ?
Asked
Active
Viewed 779 times
1

james
- 21
- 3
1 Answers
0
Try this:
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
and then
UiDevice mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
mDevice.pressBack();
Which I found here: Espresso.pressBack() does not call onBackPressed()
However, for this use case, pressing back probably isn't the workaround you want. Consider stubbing your intent instead with Intent.intending(Matcher)
so that the test doesn't leave your app.

yuval
- 6,369
- 3
- 32
- 44