I would like to click on the first matching row in recyclerView which item has descendant matching to specific text.
For now, I have
onView(withId(R.id.news)).perform(
actionOnItem(hasDescendant(withText("text")),click())
)
which throws ambiguousViewMatcherException. I tried to add first matcher from here
onView(withId(R.id.news)).perform(
actionOnItem(hasDescendant(first(withText("text"))),click())
)
but it time out.
public static Matcher<View> first(Matcher<View> expected ){
return new TypeSafeMatcher<View>() {
private boolean first = false;
@Override
protected boolean matchesSafely(View item) {
if( expected.matches(item) && !first ){
return first = true;
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("Matcher.first( " + expected.toString() + " )" );
}
};
}