espresso select first match of row in RecyclerView which descendant matching to specific text

℡╲_俬逩灬. 提交于 2019-12-10 23:05:07

问题


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() + " )" );
        }
    };
}

来源:https://stackoverflow.com/questions/47366728/espresso-select-first-match-of-row-in-recyclerview-which-descendant-matching-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!