如何在 Espresso 中的 RecyclerView 内断言? [英] How to assert inside a RecyclerView in Espresso?

查看:23
本文介绍了如何在 Espresso 中的 RecyclerView 内断言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 espresso-contrib 在 RecyclerView 上执行操作,它可以正常工作,例如:

I am using espresso-contrib to perform actions on a RecyclerView, and it works as it should, ex:

//click on first item
onView(withId(R.id.recycler_view))
    .perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));

我需要对它进行断言.像这样:

and I need to perform assertions on it. Something like this:

onView(withId(R.id.recycler_view))
    .perform(
        RecyclerViewActions.actionOnItemAtPosition(
            0, check(matches(withText("Test Text")))
        )
    );

但是,因为 RecyclerViewActions 当然,期待一个动作,它说错了第二个参数类型.espresso-contrib 上没有 RecyclerViewAssertions.

but, because RecyclerViewActions is, of course, expecting an action, it says wrong 2nd argument type. There's no RecyclerViewAssertions on espresso-contrib.

有没有办法对 RecyclerView 执行断言?

Is there any way to perform assertions on a RecyclerView?

推荐答案

您应该查看 Danny Roa 的解决方案 自定义 RecyclerView 操作并像这样使用它:

You should check out Danny Roa's solution Custom RecyclerView Actions And use it like this:

onView(withRecyclerView(R.id.recycler_view)
    .atPositionOnView(1, R.id.ofElementYouWantToCheck))
    .check(matches(withText("Test text")));

这篇关于如何在 Espresso 中的 RecyclerView 内断言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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