Problem: I'm having an issue while running my Espresso test, after the perform(click()) method is called on the login button, the test keeps running but doesn't go any further until 45 seconds pass and the test automatically fails. Meanwhile, the login happens normally.
Context: I have an Activity with two Fragments side by side, the fragment on the right handles the username and password EditTexts and also the login button. This fragment is built with a ViewAnimator and two LinearLayouts as children views, the first LinearLayout has the elements mentioned before and the second one has other stuff.
This is what happens on the UI when the login button is clicked:
@Override
public void setUILoggingIn() {
spinnerLogin.setVisibility(View.VISIBLE);
loginButton.setEnabled(false);
loginButton.setText(R.string.logging_in);
usernameText.setEnabled(false);
passwordText.setEnabled(false);
}
After authenticating with the server, this is how I handle the UI:
@Override
public void setUIAuthorized() {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
viewAnimator.showNext();
// elements on the first child of the ViewAnimator
loginButton.setEnabled(true);
spinnerLogin.setVisibility(View.GONE);
// elements on the second child of the ViewAnimator
sendMessageButton.setEnabled(true);
chatInputText.setEnabled(true);
}
});
}
Espresso Test
ViewInteraction loginButton2 = onView(withId(R.id.login_button));
loginButton2.perform(click()); // Test gets stuck here.
loginButton2.check(doesNotExist()); // Never reached.
Does anyone know hot to successfully test on this kind of scenario? It would be enough to detect when the ViewAnimator changes, but the test gets stuck on the click.
Also: That was not the beginning of the test, before the code shown before, I run this test and it works like a dream:
ViewInteraction loginButton = onView(withId(R.id.login_button));
/** Failed login **/
loginButton.perform(click());
ViewInteraction snackBarTextView = onView(
allOf(withId(R.id.snackbar_text), withText("Login error"), isDisplayed()));
snackBarTextView.check(matches(withText("Login error")));
Thank you all for your help and any advice