fernandohur fernandohur - 3 months ago 68
Android Question

Testing multiple activities with espresso

Is it possible to write tests across several activities using the android espresso framework?

Answer

Yes, it is possible. In one of the samples they have demoed this;

public void testTypingAndPressBack() {
// Close soft keyboard after type to avoid issues on devices with soft keyboard.
onView(withId(R.id.sendtext_simple))
    .perform(typeText("Have a cup of Espresso."), closeSoftKeyboard());

onView(withId(R.id.send_simple))
    .perform(click());

// Clicking launches a new activity that shows the text entered above. You don't need to do
// anything special to handle the activity transitions. Espresso takes care of waiting for the
// new activity to be resumed and its view hierarchy to be laid out.
onView(withId(R.id.display_data))
    .check(matches(withText(("Have a cup of Espresso."))));

// Going back to the previous activity - lets make sure our text was perserved.
pressBack();

onView(withId(R.id.sendtext_simple))
    .check(matches(withText(containsString("Espresso"))));
}

Read the inline comment.