在回收站视图中点击第一个匹配的文本Android espresso测试 [英] Tapping the first matching text on a recycler view Android espresso Testing

查看:96
本文介绍了在回收站视图中点击第一个匹配的文本Android espresso测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的应用程序中点击匹配文本的第一个元素. 但是,由于我当前的代码行,此刻我收到一条错误消息,告诉我有多个匹配项. onView(allOf(withId(R.id.offerSummaryLayout))).perform(RecyclerViewActions.actionOnItem(Matchers.allOf(hasDescendant(withText("Online sale"))), click()));

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

推荐答案

如果您有多个匹配项,并且只关心第一个匹配项,则可以创建一个自定义匹配器. 这里的这个应该可以正常工作.

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.

然后,您可以执行类似的操作(我简化了代码-如果只有一个条件,则不需要Matchers.allOf):

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()));

这篇关于在回收站视图中点击第一个匹配的文本Android espresso测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆