Tobias Reich Tobias Reich - 1 year ago 157
Android Question

Android Espresso - Testing on different Activities

I'm writing tests for my Android App with the Espresso framework. This seems to work fine so far. Problem is that I sometimes have to change the Activity.

In this specific case clicking a button opens the Google PlacePicker for selecting a certain position. But meanwhile this Activity is shown, Espresso is waiting for the next step. So instead of interacting in this Activity it stalls until I manually close the Place Picker (or the timeout is reached).

So it looks like this:

onView(withId(; // opens PlacePicker
onView(...) // is only executed the moment I manually close the PlacePicker

So is there an option to tell Espresso that the Activity has changed in order to select a place and return to my activity? I can't do any interaction in the PlacePicker, no view element can be found from the debugger.

Answer Source

Espresso works with only one activity. It is designed to test activities.

You can simulate PlacePicker call by manually calling your onActivityResult with some fake (manually created) Intent.

So call

onActivityResult(PLACE_PICKER_REQUEST, RESULT_OK, intent)

instead of

onView(withId(; // opens PlacePicker    
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download