Issue
I'm trying to select an item from a grid view that is located in a view pager.
The different pages in the view pager contain identical grid views (but with different content).
Is there a way to handle this somehow?
I have the following logic:
onData(new BaseMatcher<String>() {
@Override
public void describeTo(Description description) {
// what?
description.appendText("Matches A");
}
@Override
public boolean matches(Object item) {
return item instanceof String && ((String) item).equals("A");
}
}).inAdapterView(allOf(withId(R.id.grid_view))).perform(click());
Which I was hoping to start with/work on (the base matcher needs to have the matches method updated, but I can work on that next...).
However, the call fails due to:
android.support.test.espresso.AmbiguousViewMatcherException: '(with id: com.zachproject.espresso:id/grid_view)' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.
Which makes sense since multiple grid_view ids are found (one per page in the view pager).
Any ideas to make this work?
Thanks, Zach
Solution
If you add isDisplayed()
to your adapter matcher, it will only match the AdapterView
that is being displayed on the screen, which will be the AdapterView
on the current page in most cases.
allOf(withId(R.id.grid_view), isDisplayed())
Answered By - Be_Negative
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.