【发布时间】:2025-11-28 00:05:01
【问题描述】:
我有一个包含RecyclerView 的Fragment。但是由于我在这个Fragment 中有很多元素,我想向上滑动列表来查看并检查这个Fragment 中的所有元素。
以前这种方法对我有帮助,但现在由于某种原因它不起作用:
Espresso.onView(ViewMatchers.withId(R.id.recyclerView)).perform(ViewActions.swipeUp())
我的项目中有很多 RecyclerViews 和相同的 id:
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
在我的测试中我也写过这样的东西:
onView(allOf( withId(R.id.recyclerView), isDisplayed()))
onView(withId(R.id.recyclerView)).perform(swipeUp())
但只在第二行发现错误。
android.support.test.espresso.AmbiguousViewMatcherException: 'with id: com.fentury.android:id/recyclerView' 匹配层次结构中的多个视图。 问题视图在下方标有“**** MATCHES****”。
【问题讨论】:
-
澄清 “不起作用” 应该是什么意思。显示您的视图层次结构,以便我们了解可能出了什么问题。
标签: android android-fragments android-recyclerview swipe android-espresso