看起来像是CoordinatorLayout破坏了 Espresso 操作的行为,例如scrollTo()or RecyclerViewActions.scrollToPosition()。
NestedScrollView 的问题
对于这样的布局:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
...
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
...
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
如果我尝试滚动到NestedScrollView使用里面的任何视图ViewActions.scrollTo(),我发现的第一个问题是我得到一个PerformException. 这是因为这个动作只支持ScrollView而NestedScrollView不是扩展它。这里解释了这个问题的解决方法,基本上我们可以复制代码scrollTo()并更改约束以支持NestedScrollView。NestedScrollView如果不在 a 中,这似乎可行,CoordinatorLayout但只要将其放入 a 中CoordinatorLayout,滚动操作就会失败。
RecyclerView 的问题
对于相同的布局,如果我NestedScrollView用 a替换RecyclerView,滚动也会出现问题。
在这种情况下,我使用RecyclerViewAction.scrollToPosition(position). 与 不同NestedScrollView,在这里我可以看到一些滚动发生。但是,它看起来像滚动到错误的位置。例如,如果我滚动到最后一个位置,它会显示倒数第二个而不是最后一个。当我将滚动作品RecyclerView移出时,它应该是。CoordinatorLayout
CoordinatorLayout由于这个问题,目前我们无法为使用的屏幕编写任何 Espresso 测试。有人遇到同样的问题或知道解决方法吗?