用于 viewpager 列表视图的 Espresso 2.0 AmbiguousViewMatcherException
Posted
技术标签:
【中文标题】用于 viewpager 列表视图的 Espresso 2.0 AmbiguousViewMatcherException【英文标题】:Espresso 2.0 AmbiguousViewMatcherException for viewpager listviews 【发布时间】:2015-10-01 11:58:45 【问题描述】:当我尝试在测试下运行时,我得到了 AmbiguousViewMatcherException,我怎样才能从多个视图中获得预期的视图。
onData(hasToString(startsWith("ALS"))).inAdapterView(allOf(withId(android.R.id.list))).atPosition(0).perform(click());
android.support.test.espresso.AmbiguousViewMatcherException: '(with id: android:id/list)' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.
View Hierarchy:
+>DecorViewid=-1, visibility=VISIBLE, width=1440, height=2560, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3
|
+->LinearLayoutid=-1, visibility=VISIBLE, width=1440, height=2392, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2
|
+-->ViewStubid=16909171, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0
|
+-->FrameLayoutid=16908290, res-name=content, visibility=VISIBLE, width=1440, height=2304, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=88.0, child-count=1
|
+--->ViewPagerid=2131558505, res-name=pager, visibility=VISIBLE, width=1440, height=2304, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3
|
+---->KayakPagerTabStripid=2131558506, res-name=tabstrip, visibility=VISIBLE, width=1440, height=112, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3
|
+----->TextViewid=-1, visibility=VISIBLE, width=0, height=66, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=25.0, text=, input-type=0, ime-target=false, has-links=false
|
+----->TextViewid=-1, visibility=VISIBLE, width=56, height=66, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=692.0, y=25.0, text=All, input-type=0, ime-target=false, has-links=false
|
+----->TextViewid=-1, visibility=VISIBLE, width=201, height=66, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=1239.0, y=25.0, text=Favorites, input-type=0, ime-target=false, has-links=false
|
+---->FrameLayoutid=-1, visibility=VISIBLE, width=1440, height=2192, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=112.0, child-count=2
|
+----->LinearLayoutid=16711682, visibility=VISIBLE, width=1440, height=2192, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1
|
+------>ProgressBarid=-1, visibility=VISIBLE, width=266, height=266, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=587.0, y=963.0
|
+----->FrameLayoutid=16711683, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2
|
+------>TextViewid=16711681, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false
|
+------>ListViewid=16908298, res-name=list, visibility=VISIBLE, 宽度=0,高度=0,有焦点=假,有焦点=假, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false,is-focusable=false,is-layout-requested=true, is-selected=false,root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0 ****比赛****
|
+---->FrameLayoutid=-1, visibility=VISIBLE, width=1440, height=2192, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=1440.0, y=112.0, child-count=2
|
+----->LinearLayoutid=16711682, visibility=VISIBLE, width=1440, height=2192, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1
|
+------>ProgressBarid=-1, visibility=VISIBLE, width=266, height=266, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=587.0, y=963.0
|
+----->FrameLayoutid=16711683, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2
|
+------>TextViewid=16711681, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false
|
+------>ListViewid=16908298, res-name=list, visibility=VISIBLE, 宽度=0,高度=0,有焦点=假,有焦点=假, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false,is-focusable=false,is-layout-requested=true, is-selected=false,root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0 ****比赛****
|
+->Viewid=16908335, res-name=statusBarBackground, visibility=VISIBLE, width=1440, height=88, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0
|
+->Viewid=16908336, res-name=navigationBarBackground, visibility=VISIBLE, width=1440, height=168, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=2392.0
|
【问题讨论】:
【参考方案1】:您可以将isDisplayed()
添加到您的适配器视图匹配器中,以与当前可见的列表视图进行交互。
inAdapterView(allOf(withId(android.R.id.list), isDisplayed()))
【讨论】:
以上是关于用于 viewpager 列表视图的 Espresso 2.0 AmbiguousViewMatcherException的主要内容,如果未能解决你的问题,请参考以下文章
获取为 ViewPager 打开视图的时间(以 ms 为单位)