测试RecyclerView:RecyclerViewActions滚动不够远 [英] Testing a RecyclerView: RecyclerViewActions isn't scrolling far enough
问题描述
我希望我的意式浓缩咖啡测试向下滚动RecyclerView,直到看到某个视图并单击它为止.
I want my espresso test to scroll a RecyclerView down until it's sees a certain view and clicks it.
因此,我正在使用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%.点击通话因此而崩溃.
The test scrolls the RecyclerView down, but only about 50% of the needed amount. The click call crashes because of it.
有人遇到过类似的事情吗?
Does somebody encountered something similar?
谢谢!
推荐答案
我已经找到了视图操作未成功的原因:
I've found the reason why the view action wasn't successul:
该应用程序具有可折叠的工具栏,在我开始滚动操作之前已对其进行了扩展.当我执行滚动操作时,工具栏首先折叠,然后滚动了回收站视图.因此,回收站视图滚动到很少.
The app has a collapsible toolbar which was expanded before I started the scroll action. When I performed the scroll action the toolbar collapsed first and then the recycler view scrolled. Therefore the recycler view scrolled to little.
我找到的解决方案是,我首先使用自定义AppBarViewAction折叠工具栏.在此处
The solution I found is that I collapse the toolbar first with a custom AppBarViewAction. The solution is found here
这篇关于测试RecyclerView:RecyclerViewActions滚动不够远的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!