Espresso test stuck / inactive after execution (press ()) on a button in ViewAnimator

Problem: I had a problem starting the Espresso test after the call (click ()) method is called on the login button, the test continues to work, but does not go on until 45 seconds have passed, and the test will automatically fail. Meanwhile, registration usually happens.

Context: I have activity with two fragments side by side, the fragment on the right handles the EditTexts username and password, as well as the login button. This fragment is built using ViewAnimator and two LinearLayouts in the form of children's representations, the first LinearLayout has the elements mentioned above, and the second has another.

This is what happens in the user interface 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 authentication with the server, I process the user interface:

 @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 that you need to successfully test this scenario? It would be enough to detect when the ViewAnimator changes, but the test is stuck on a click.

Also: This was not the beginning of the test, before the code shown earlier, 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 🌚😄

+6
source share
2 answers

I had a similar problem, and in my case it was a progress indicator that was uploaded to a fragment that did not display. This progress was not rejected by mistake and blocked the tests. I had the same result when the tests failed after 45 seconds got stuck as you described. To summarize, make sure that there is no animation in the user interface thread as a progress bar or whatever.

+6
source

I had the same problem when I was working with ListView.

Interestingly, I noticed that the test will resume if I manually try to scroll the screen. Adding this line solved the problem and resumed testing.

onView(withId(R.id.myListView)).perform(swipeUp());

0
source

All Articles