如何在Espresso中的RecyclerView内断言? [英] How to assert inside a RecyclerView in Espresso?
问题描述
我正在使用espresso-contrib在 RecyclerView
上执行操作,并且它可以正常工作,例如:
I am using espresso-contrib to perform actions on a RecyclerView
, and it works as it should, ex:
onView(withId(R.id.recycler_view))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click())); //click on first item
我需要对它执行断言。这样的事情:
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"))));
但是,因为< a href =http://android-test-kit.googlecode.com/git-history/e81b6694887f5c73617759d2728a92beba9b8f12/docs/javadocs/espresso/espresso-contrib-2.0-javadoc/reference/android/support/test/espresso/contrib/ RecyclerViewActions.html#actionOnItemAtPosition(int,%20android.support.test.espresso.ViewAction)rel =noreferrer> RecyclerViewActions 当然是期待一个动作,它说错误的第二个参数类型。没有< espresso-contrib上的code> RecyclerViewAssertions 。
but, because RecyclerViewActions is, of course, expecting an action, it says wrong 2nd argument type. There's no RecyclerViewAssertions
on espresso-contrib.
有没有办法在回收站视图上执行断言?
Is there any way to perform assertions on a recycler view?
推荐答案
你应该看看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屋!