Reputation: 16278
I'm testing it using the following:
onView(allOf(withId(android.support.design.R.id.snackbar_text), withText("Network Error")))
.check(matches(isDisplayed()));
But it fails on is displayed on the screen to the user
most likely because the y
coordinate is 0
: ... x=18.0, y=0.0, ...
Full log:
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}"
Any ideas?
Upvotes: 2
Views: 2089
Reputation: 14125
You can use withEffectiveVisibility instead of isDisplayed so it doesn't matter whether it is actually displayed in the current screen:
private void checkSnackBarDisplayedByMessage(@StringRes int message) {
onView(allOf(withId(android.support.design.R.id.snackbar_text), withText(message)))
.check(matches(withEffectiveVisibility(
ViewMatchers.Visibility.VISIBLE
)));
}
Upvotes: 4