1

We have a View Pager in our app that when a user is signed out we show the same UI. So since the UI is the same for each page on the view pager tapping on an element or checking if it is displayed just gives me the Matches multiple error. So my theory is since view pagers load everything at once that is why i get this error. Changing the contentDescriptor doesn't work since it will be the same in all views.

The view is of a button when not signed in and when signed in it will have a grid view.

So my question is - how do I get to the button or whatever element I may need? I cannot change the app code.

Using Espresso 2.2.2

Skycamefalling
  • 308
  • 1
  • 12

1 Answers1

0

Yes, the problem is that the ViewPager creates at least the View to the left and right of the currently visible View. And Espresso uses all matchers in onView on every View in the hierarchy, regardless if it is on the screen or not.

If just one of the Views you want to match is currently visible, then use isDisplayed to match the View that is currently on the screen:

// Matches a view that is on the screen AND has the id R.id.some_button
onView(allOf(isDisplayed(), withId(R.string.some_id))).check(matches(isDisplayed()));

If you do not check() or perform() after you have matched a View with onView() the test will not fail! So if you want to check if a View is visible, then you have to check(matches(isDisplayed())) too.

thaussma
  • 9,756
  • 5
  • 44
  • 46