如何使用 Espresso 测试嵌套的 RecyclerView(RecyclerView 内的 RecyclerView)
How to test nested RecyclerView (RecyclerView inside RecyclerView) with Espresso
我在另一个 RecyclerView(parentRecyclerView) 中实现了 RecyclerView(childRecyclerView),下图说明了所有实现:
我想编写一个 espresso 测试来检查 childRecyclerView 中的所有 TextView 是否具有预期的文本,我已经检查了这个答案 ,所以在我的例子中是这样的:
onView(allOf(isDescendantOfA(withRecyclerView(R.id.parentRecyclerView).atPosition(0)),
isDescendantOfA(withRecyclerView(R.id.childRecyclerView).atPosition(0)),
withId(R.id.textView1)))
.check(matches(withText("some text")));
没关系,但我遇到的问题是,当我在 withRecyclerView(R.id.parentRecyclerView).atPosition(0)
中为 atPosition 传递 1 时,我收到一条错误消息,指出在层次结构中找不到该视图:
No views in hierarchy found matching: (is descendant of a: RecyclerView with id: com.example.testapp:id/parentRecyclerView at position: 1
还有其他方法可以测试 childRecyclerView 内容吗?
我用过这个并且有效:
onView(withId(R.id.parentRecyclerView))
.perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(0))
onView(
allOf(
isDescendantOfA(allOf(
withId(R.id.contentRootLayout),
hasDescendant(withText("title text"))
)),
isDescendantOfA(withId(R.id.childRecyclerView)),
withId(R.id.textView1),
withText("some text")
)
).check(matches(isDisplayed()))
我在另一个 RecyclerView(parentRecyclerView) 中实现了 RecyclerView(childRecyclerView),下图说明了所有实现:
我想编写一个 espresso 测试来检查 childRecyclerView 中的所有 TextView 是否具有预期的文本,我已经检查了这个答案
onView(allOf(isDescendantOfA(withRecyclerView(R.id.parentRecyclerView).atPosition(0)),
isDescendantOfA(withRecyclerView(R.id.childRecyclerView).atPosition(0)),
withId(R.id.textView1)))
.check(matches(withText("some text")));
没关系,但我遇到的问题是,当我在 withRecyclerView(R.id.parentRecyclerView).atPosition(0)
中为 atPosition 传递 1 时,我收到一条错误消息,指出在层次结构中找不到该视图:
No views in hierarchy found matching: (is descendant of a: RecyclerView with id: com.example.testapp:id/parentRecyclerView at position: 1
还有其他方法可以测试 childRecyclerView 内容吗?
我用过这个并且有效:
onView(withId(R.id.parentRecyclerView))
.perform(RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(0))
onView(
allOf(
isDescendantOfA(allOf(
withId(R.id.contentRootLayout),
hasDescendant(withText("title text"))
)),
isDescendantOfA(withId(R.id.childRecyclerView)),
withId(R.id.textView1),
withText("some text")
)
).check(matches(isDisplayed()))