Snack and espresso sometimes

As the name says, it fails several times, some others fail.

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is displayed on the screen to the user' doesn't match the selected view. Expected: is displayed on the screen to the user Got: "AppCompatTextView{id=2131492981, res-name=snackbar_text, visibility=VISIBLE, width=444, height=71, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=18.0, y=0.0, text=Network Error, input-type=0, ime-target=false, has-links=false}" 

The first line of the stack trace shows that the espresso cannot see the Snackbar on the screen. But the second line claims that in fact it looks like there is a Snackbar with visibility=VISIBLE and text=Network Error .

I'm confused, what's going on?

This is my test code:

 activityRule.launchActivity(new Intent()); onView(withText("Network Error")).check(matches(isDisplayed())); 

PS: basically it fails when I run the entire test suit; but sometimes it also fails when I just run this test myself. In some other cases, it goes green, but there is no pattern that seems random.

+6
source share
2 answers

Late! But I hope this is helpful to others:

Espresso Snack Show Testing

 private void checkSnackBarDisplayedByMessage(@StringRes int message) { onView(withText(message)) .check(matches(withEffectiveVisibility( ViewMatchers.Visibility.VISIBLE ))); } 
+4
source

I had a similar problem. I was able to solve this:

  • Dismantling the animations described here .

  • I showed SnackBar after I received the data from the server, so I also had to wait until the data was received. I managed to solve it using IdlingResource as described in this anwser.

Then I was able to successfully test SnackBar.

Hope my points help.

+1
source

All Articles