9

In Android Studio, in the androidTest folder, I have this test case:

@RunWith(AndroidJUnit4.class)
@LargeTest
public class LoginActivityTest {

    @Rule
    public ActivityTestRule<LoginActivity> activityTestRule =
            new ActivityTestRule<>(LoginActivity.class);

    @Test
    public void teamsListIsSortedAlphabetically() {
        onView(withId(R.id.etEmail)).perform(click(), replaceText("asd@asd.vf")
        );
        onView(withId(R.id.etPassword)).perform(click(), replaceText("asdasd")
        );
        onView(withId(R.id.bLoginSubmit)).perform(click());
    }
}

The app launches LoginActivity, logs in, the next activity is shown for 1-2 seconds and then it exits the activity leaving me on the launcher screen. How do I make Espresso stay on that screen?

Kaloyan Roussev
  • 14,515
  • 21
  • 98
  • 180
  • Possible duplicate of [leave Android app in final state on espresso test completion](http://stackoverflow.com/questions/29950640/leave-android-app-in-final-state-on-espresso-test-completion) – Sky Kelsey Feb 03 '16 at 08:14
  • You might wanna check out this question: http://stackoverflow.com/questions/42299276/android-directly-launch-the-activity-fragment-that-is-under-development – Marco Romano Feb 24 '17 at 12:47

1 Answers1

10

Sorry, but it's impossible.

Please read this Google reference: Automating User Interface Tests

Espresso, Robotium, Calabash and other UI test frameworks were made for short interaction testing events. It simulates an user's specific behavior - run app, do some tricks and (if successful) than close an app.

Of course, Espresso allow you to create custom idling resources and than register it in app.

The simplest way to hibernate a test for a specific amount of time is use method Thread.sleep(time_in_miliseconds), but like I said it's against idea of automated testing.

kos
  • 1,770
  • 2
  • 19
  • 41
piotrek1543
  • 19,130
  • 7
  • 81
  • 94