我已经在另一个RecyclerView(parentRecyclerView)中实现了RecyclerView(childRecyclerView),图片blow解释了所有的实现:

我想写一个espresso测试来检查childRecyclerView中的所有TextViews都是预期的文本,我已经检查了这个答案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时,我得到一个错误,指出在层次结构中找不到该视图:
No views in hierarchy found matching: (is descendant of a: RecyclerView with id: com.example.testapp:id/parentRecyclerView at position: 1有没有其他方法来测试childRecyclerView内容?
发布于 2021-03-28 06:12:47
我用了这个,它起作用了:
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()))https://stackoverflow.com/questions/62750213
复制相似问题