【发布时间】:2016-08-18 14:40:30
【问题描述】:
是否可以在 ViewPager 中单击 ListView 的第一项?
我已经尝试让它像这样工作:
onData(anything()).inAdapterView(withId(R.id.myListView)).atPosition(0).perform(click());.
但据我了解:Testing ViewPager with Espresso. How perfom action to a button of an Item? 您不能将 onData 用于 ViewPager。 另外,如果我运行测试,我会得到多个匹配项的 AmbiguousViewMatcherException。
android.support.test.espresso.AmbiguousViewMatcherException: 'with id: my.awesome.app:id/myListView' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.
如果我像这样onView(allOf(withId(R.id.myListView),isDisplayed())).perform(click()); 运行测试,则永远不会单击第一项。
还有其他方法可以单击列表的第一项吗?
【问题讨论】:
-
你只是想选择第一个项目吗?
-
不,我想点击它
-
哦,我明白了,哈哈。 @PatrickSturm
标签: android listview android-viewpager android-espresso ui-testing