Espresso嵌套回收器视图UI测试

时间:2017-03-29 08:55:58

标签: java android android-recyclerview ui-testing android-espresso

我在垂直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的第一行。

如何点击第二行父.htaccess的子RecyclerView上的元素?

1 个答案:

答案 0 :(得分:4)

我终于找到了解决方案:

onView(allOf(
         withId(R.id.childHorizontalRecyclerView),
         withParent(
           withRecyclerView(R.id.parentVerticalRecyclerView).atPosition(2)
         )
       )
).perform(RecyclerViewActions.actionOnItemAtPosition(3, scrollTo()))
.check(matches(hasDescendant(withText("USA"))));