android - 如何使用 Espresso 测试嵌套的 RecyclerView(RecyclerView 内的 RecyclerView)

标签 android testing android-recyclerview android-espresso nestedrecyclerview

我在另一个 RecyclerView(parentRecyclerView) 中实现了 RecyclerView(childRecyclerView),图片说明了所有的实现:
enter image description here
我想编写一个 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/

相关文章:

java - 如何检查地理坐标是否沿着路线?

java - 编程时如何使用Calc(或Excel)减少重复的代码编辑?

ruby-on-rails - 如何为复杂的 Rails 索引编写集成测试(最佳实践)

unit-testing - 从批处理文件设置错误级别

android - 垂直 recyclerView 中带有 wrap_content 的水平 recyclerView

android - 将点击监听器添加到通用 RecyclerView 适配器

android - 如何使用shell命令创建local.properties

java - Webview 在 Ice Cream Sandwich 中显示白色空白页面

python - 如何使用 behave 框架中的 fixture 使 selenium webdriver 作为 before_tag Hook 的一部分运行?

Android 用 TalkBack 迭代 RecycleView 的隐藏项