I've just started using Espresso, before that I have tried Robotium. I need to test LoginActivity. The logic is:
testLogin source:
public void testLogin() throws Exception{
onView(withId(R.id.login_email)).perform(typeText(LOGIN_EMAIL));
onView(withId(R.id.login_password)).perform(typeText(LOGIN_PASSWORD));
onView(withId(R.id.login_loginBtn)).perform(click());
onView(withText(R.string.loading_logging_in)).check(matches(isDisplayed()));
onView(withText("You're logged in")).check(matches(isDisplayed()));
}
The problem was that espresso didn't wait for "You"re logged in" string to appear, it was trying to find it while logging still was in process.
logcat:
com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException: No views in hierarchy found matching: with text: is "You're logged in"
I've tried using Thread.sleep(10000), but it terminates the run on Thread.sleep(10000) and gives me error:
Test failed to run to completion. Reason: 'Instrumentation run failed due to 'Process crashed.''. Check device logcat for details Test running failed: Instrumentation run failed due to 'Process crashed.'
logcat:
@@@ @@@ @@@was killed cancelService in HttpReRegistrationService
Before that, I used the waitForActivity(MainActivity.class) method. Is there any workaround to make this work?
If your login process is busy while trying to log in the user and you're not using AsyncTask (in an appropriate way) your only option is to have your busy resource to implement the interface IdlingResource
as described here.
That way Espresso knows when and how long to wait.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With