How to wait for another activity to start with Espresso?

How can I run a test that waits for an action to start each time the button is clicked?

My test is very simple:

public void testStartsNewActivity() { onView(withId(R.id.button)).perform(click()); // assert new Activity is launched } 

thanks!

+5
source share
1 answer

Claiming that a new action has been started is as simple as claiming that a view related to this new action is displayed on the screen.

Check this one for more samples. On the same page:

By default, Espresso waits for UI events in the current message queue to process and, by default, AsyncTasks * to complete before proceeding to the next test operation. This should apply to most applications / test sync in your application.

Thus, given your “really simple” test case, I assume that there is no need to wait for user resources to load and state that the displayed view should be enough.

+1
source

All Articles