【问题标题】:Espresso Nested Recycler Views UI testingEspresso Nested Recycler Views UI 测试
【发布时间】:2017-03-29 08:55:57
【问题描述】:

我在垂直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上的元素?

【问题讨论】:

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


    【解决方案1】:

    我终于找到了解决办法:

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

    【讨论】:

    • 初始匹配器有什么问题?
    • 我认为问题在于我使用的是 isDescendantOfA。 Espresso 无法找到视图。
    猜你喜欢
    • 2021-03-31
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 2018-01-26
    • 2018-10-26
    • 2021-10-18
    • 2019-10-25
    • 1970-01-01
    相关资源
    最近更新 更多