我在另一个 RecyclerView(parentRecyclerView) 中实现了 RecyclerView(childRecyclerView),图片说明了所有的实现:
我想编写一个 espresso 测试来检查 childRecyclerView 中的所有 TextView 是否与预期的文本一致,我已经检查了这个答案 https://stackoverflow.com/a/34141230/3522182 ,所以在我的情况下是这样的:
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 时我收到一个错误,指出在层次结构中找不到 View :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()))
关于android - 如何使用 Espresso 测试嵌套的 RecyclerView(RecyclerView 内的 RecyclerView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62750213/