Tapping the first matching text on a recycler view Android espresso Testing

别说谁变了你拦得住时间么 提交于 2020-01-05 07:32:50

问题


I am trying to tap on the first element of a matching text in my app. However at the moment i am receiving an error telling me there are multiple matches due to my current line of code. onView(allOf(withId(R.id.offerSummaryLayout))).perform(RecyclerViewActions.actionOnItem(Matchers.allOf(hasDescendant(withText("Online sale"))), click()));

How can I change this so it clicks on the first matching element? Thanks in advance


回答1:


If you have multiple matches and you only care about the first one, you can create a custom matcher. This one here should work just fine.

Then you can do things like that (I simplified your code a bit - you don't need Matchers.allOf if you have only a single condition):

onView(withId(R.id.offerSummaryLayout)).perform(RecyclerViewActions
        .actionOnItem(first(hasDescendant(withText("Online sale"))), click()));


来源:https://stackoverflow.com/questions/42957747/tapping-the-first-matching-text-on-a-recycler-view-android-espresso-testing

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