I just started using Espresso, before that I tried Robotium. I need to test LoginActivity. The logic is this:
- The user enters the correct credentials;
- The user sees the line "Logging in ..";
- The user waits until the line disappears;
- The user is in MainActivity and sees "You are logged in."
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 the espresso did not wait for the line “You entered the line” to appear, she tried to find it while the log was not yet running.
LogCat:
com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException: No views in the hierarchy found a match: with the text: "You are logged in"
Thread.sleep(10000), Thread.sleep(10000) :
. : " -" ". - . : - .
LogCat:
@@@@@@@@@ cancelService HttpReRegistrationService
waitForActivity (MainActivity.class).
?