Espresso 嵌套回收器视图 UI 测试
Espresso Nested Recycler Views UI testing
我在垂直 RecyclerView
中有一个水平 RecyclerView
。我正在使用我在其他问题上找到的这段代码:
onView(allOf(isDescendantOfA(withRecyclerView(R.id.parentVerticalRecyclerView).atPosition(parentPosition)),
isDescendantOfA(withRecyclerView(R.id.childHorizontalRecyclerView).atPosition(childPosition)),
(withText("USA"))))
.perform(click());
// It is not working for parentPosition > 0
但这仅适用于父级的第一行 RecyclerView
。
如何点击父RecyclerView
第二行的子RecyclerView上的元素?
我终于想出了解决办法:
onView(allOf(
withId(R.id.childHorizontalRecyclerView),
withParent(
withRecyclerView(R.id.parentVerticalRecyclerView).atPosition(2)
)
)
).perform(RecyclerViewActions.actionOnItemAtPosition(3, scrollTo()))
.check(matches(hasDescendant(withText("USA"))));
我在垂直 RecyclerView
中有一个水平 RecyclerView
。我正在使用我在其他问题上找到的这段代码:
onView(allOf(isDescendantOfA(withRecyclerView(R.id.parentVerticalRecyclerView).atPosition(parentPosition)),
isDescendantOfA(withRecyclerView(R.id.childHorizontalRecyclerView).atPosition(childPosition)),
(withText("USA"))))
.perform(click());
// It is not working for parentPosition > 0
但这仅适用于父级的第一行 RecyclerView
。
如何点击父RecyclerView
第二行的子RecyclerView上的元素?
我终于想出了解决办法:
onView(allOf(
withId(R.id.childHorizontalRecyclerView),
withParent(
withRecyclerView(R.id.parentVerticalRecyclerView).atPosition(2)
)
)
).perform(RecyclerViewActions.actionOnItemAtPosition(3, scrollTo()))
.check(matches(hasDescendant(withText("USA"))));