我正在尝试测试使用ViewPager
的应用程序。每个页面包含多个片段,但这些片段并不总是可见的。我想检查当前可见页面中片段的可见性。
onView(withId(R.id.container_weather))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)));
但问题是浓缩咖啡外观都在所有页面上显示,而不仅仅是当前页面,我会得到以下错误:
android.support.test.espresso.AmbiguousViewMatcherException: 'with id: eu.airpatrol.android:id/container_weather' 匹配层次结构中的多个视图...
allOf()
中添加这个检查。 - denysallOf()
解决了我的问题(谢谢),但请注意,您很可能希望匹配isDisplayed()
或isCompletelyDisplayed()
而不是withEffectiveVisibility()
,因为后者方法基于View
的visibility
属性进行匹配,而不是屏幕上是否实际可见。 - Adil Hussain