我希望我的espresso测试能够向下滚动RecyclerView,直到它看到某个视图并点击它。
因此我使用RecyclerViewActions
:
onView(withId(R.id.recycler)).perform(
RecyclerViewActions.scrollTo<RecyclerView.ViewHolder>(
hasDescendant(withText(R.string.title_item_x))
)
)
Thread.sleep(2000)
onView(withId(R.id.recycler)).perform(
RecyclerViewActions.actionOnItem<RecyclerView.ViewHolder>(
hasDescendant(withText(R.string.title_item_x)),
click()
)
)
测试向下滚动RecyclerView,但只占所需数量的50%左右。点击通话因此而崩溃。
有人遇到过类似的东西吗?
谢谢!
答案 0 :(得分:0)
我找到了为什么视图操作没有成功的原因:
该应用有一个可折叠工具栏,在我开始滚动操作之前已展开。当我执行滚动操作时,工具栏首先折叠,然后滚动回收器视图。因此,回收者视图滚动到很少。
我找到的解决方案是首先使用自定义AppBarViewAction折叠工具栏。找到解决方案here