android - Find footer in integration test using Espresso -


i have custom adapter mycustomadapter extends baseadapter. have listview add footerview it:

    protected listview mitemslist;      // adapter     protected mycustomadapter madapter;     @visiblefortesting     public static final string footer = "footer";  view footerview = layoutinflater.from(this).inflate(r.layout.footer_view, mitemslist, false); mitemslist.addfooterview(footerview, footer, true); 

now want find footer , test with espresso. code using:

public void testclickfooter() {      ondata(isfooter()).perform(click()); }  private matcher<object> isfooter() {   // depends on activity.footer being passed data in addfooterview method.      return allof(is(instanceof(string.class)), is(checklistbaseactivity.footer)); } 

it fails , receive following error:

com.google.android.apps.common.testing.ui.espresso.ambiguousviewmatcherexception: 'is assignable class: class android.widget.adapterview' matches multiple views in hierarchy. problem views marked '****matches****' below.  view hierarchy: +>decorview{id=-1, visibility=visible, width=540, height=960, has-focus=true, 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=1} | +->actionbaroverlaylayout{id=16909238, res-name=action_bar_overlay_layout, visibility=visible, width=540, height=960, has-focus=true, 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} | +-->framelayout{id=16908290, res-name=content, visibility=visible, width=540, height=850, has-focus=true, 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=110.0, child-count=1} | +--->relativelayout{id=-1, visibility=visible, width=540, height=850, has-focus=true, 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} | +---->relativelayout{id=2131361812, res-name=header, visibility=visible, width=540, height=60, 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=3} | +----->networkimageview{id=2131361889, res-name=image_header_thumbnail, visibility=invisible, width=54, height=48, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, 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=6.0, y=6.0} | +----->textview{id=2131361890, res-name=text_header_title, visibility=visible, width=408, height=60, 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=66.0, y=0.0, text=add new checklist, input-type=0, ime-target=false} | +----->space{id=2131362013, res-name=space_header, visibility=invisible, width=54, height=48, 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=480.0, y=6.0} | +---->listview{id=2131361813, res-name=list_checklist_items, visibility=visible, width=516, height=718, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=true, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=12.0, y=60.0, child-count=2} ****matches**** | +----->relativelayout{id=-1, visibility=visible, width=516, height=167, 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=true, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3} | +------>edittext{id=2131362006, res-name=text_checklist_title, visibility=visible, width=516, height=57, 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=true, root-is-layout-requested=false, has-input-connection=true, editor-info=[inputtype=0x4001 imeoptions=0xc000006 privateimeoptions=null actionlabel=null actionid=0 initialselstart=0 initialselend=0 initialcapsmode=0x2000 hinttext=title label=null packagename=null fieldid=0 fieldname=null extras=null ], x=0.0, y=12.0, text=, hint=title, input-type=16385, ime-target=false} | +------>linearlayout{id=2131362007, res-name=checklist_template_extras_container, visibility=visible, width=516, height=60, 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=true, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=81.0, child-count=2} | +------->framelayout{id=2131362011, res-name=layout_image_selection, visibility=visible, width=332, height=60, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=true, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1} | +-------->textview{id=2131362012, res-name=text_choose_image, visibility=visible, width=168, height=60, 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=true, root-is-layout-requested=false, has-input-connection=false, x=82.0, y=0.0, text=välj bild/ikon, input-type=0, ime-target=false} | +------->spinner{id=2131361848, res-name=spinner_color_selection, visibility=invisible, width=172, height=60, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=true, root-is-layout-requested=false, has-input-connection=false, x=344.0, y=0.0, child-count=0} ****matches**** | +------>view{id=2131362008, res-name=border_checklist_title, visibility=visible, width=516, height=2, 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=true, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=153.0} | +----->linearlayout{id=2131361978, res-name=layout_add_new_checklist_item, visibility=visible, width=516, height=125, 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=169.0, child-count=3} | +------>view{id=2131361979, res-name=list_footer, visibility=visible, width=516, height=8, 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} | +------>linearlayout{id=2131361980, res-name=checkbox_checklist_item_new, visibility=visible, width=516, height=57, 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=8.0, child-count=2} | +------->checkbox{id=2131361981, res-name=checkbox_checklist_item_done, visibility=visible, width=36, height=36, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=false, 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=11.0, text=, input-type=0, ime-target=false, is-checked=false} | +------->edittext{id=2131361982, res-name=text_checklist_item_description, desc=description, visibility=visible, width=480, height=57, 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=true, editor-info=[inputtype=0x4001 imeoptions=0xc000005 privateimeoptions=null actionlabel=null actionid=0 initialselstart=0 initialselend=0 initialcapsmode=0x2000 hinttext=null label=null packagename=null fieldid=0 fieldname=null extras=null ], x=36.0, y=0.0, text=, input-type=16385, ime-target=false} | +------>imagebutton{id=2131361983, res-name=button_add_checklist_item, visibility=visible, width=60, height=60, 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=65.0} | +---->relativelayout{id=2131361814, res-name=layout_button_row, visibility=visible, width=540, height=72, 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=778.0, child-count=2} | +----->view{id=2131361976, res-name=footer_divider, visibility=visible, width=540, height=2, 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} | +----->linearlayout{id=-1, visibility=visible, width=540, height=70, 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=2.0, child-count=2} | +------>textview{id=2131361917, res-name=btn_cancel, visibility=visible, width=397, height=60, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, 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=9.0, text=cancel, input-type=0, ime-target=false} | +------>textview{id=2131361977, res-name=btn_add, visibility=visible, width=143, height=64, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, 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=397.0, y=6.0, text=add, input-type=0, ime-target=false} | +-->actionbarcontainer{id=16909239, res-name=action_bar_container, visibility=visible, width=540, height=72, 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=38.0, child-count=2} | +--->actionbarview{id=16909240, res-name=action_bar, visibility=visible, width=540, height=72, 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} | +---->linearlayout{id=-1, desc=keeptrack, navigate up, visibility=visible, width=217, height=72, 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=0.0, child-count=2} | +----->homeview{id=-1, visibility=visible, width=84, height=72, 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=2} | +------>imageview{id=16908981, res-name=up, visibility=visible, width=24, height=24, 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=24.0} | +------>imageview{id=16908332, res-name=home, visibility=visible, width=48, height=48, 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=30.0, y=12.0} | +----->linearlayout{id=-1, visibility=visible, width=133, height=37, 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=84.0, y=17.0, child-count=2} | +------>textview{id=16909003, res-name=action_bar_title, visibility=visible, width=121, height=37, 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, text=keeptrack, input-type=0, ime-target=false} | +------>textview{id=16909004, res-name=action_bar_subtitle, 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} | +---->actionmenuview{id=-1, visibility=visible, width=0, height=72, 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=540.0, y=0.0, child-count=0} | +--->actionbarcontextview{id=16909241, res-name=action_context_bar, 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=0} | +-->actionbarcontainer{id=16909242, res-name=split_action_bar, 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=0} | @ dalvik.system.vmstack.getthreadstacktrace(native method) @ java.lang.thread.getstacktrace(thread.java:579) @ com.google.android.apps.common.testing.ui.espresso.base.defaultfailurehandler.getuserfriendlyerror(defaultfailurehandler.java:69) @ com.google.android.apps.common.testing.ui.espresso.base.defaultfailurehandler.handle(defaultfailurehandler.java:40) @ com.google.android.apps.common.testing.ui.espresso.viewinteraction.runsynchronouslyonuithread(viewinteraction.java:159) @ com.google.android.apps.common.testing.ui.espresso.viewinteraction.doperform(viewinteraction.java:90) @ com.google.android.apps.common.testing.ui.espresso.viewinteraction.perform(viewinteraction.java:73) @ com.google.android.apps.common.testing.ui.espresso.datainteraction.load(datainteraction.java:135) @ com.google.android.apps.common.testing.ui.espresso.datainteraction.perform(datainteraction.java:112) @ se.comai.keeptrack.espresso.activity.checklisttemplateactivitytest.testclickfooter(checklisttemplateactivitytest.java:40) @ java.lang.reflect.method.invokenative(native method) @ android.test.instrumentationtestcase.runmethod(instrumentationtestcase.java:214) @ android.test.instrumentationtestcase.runtest(instrumentationtestcase.java:199) @ android.test.activityinstrumentationtestcase2.runtest(activityinstrumentationtestcase2.java:192) @ android.test.androidtestrunner.runtest(androidtestrunner.java:191) @ android.test.androidtestrunner.runtest(androidtestrunner.java:176) @ android.test.instrumentationtestrunner.onstart(instrumentationtestrunner.java:554) @ com.google.android.apps.common.testing.testrunner.googleinstrumentationtestrunner.onstart(googleinstrumentationtestrunner.java:167) @ android.app.instrumentation$instrumentationthread.run(instrumentation.java:1729) 

why happens , solution?

as error shows problem views marked '****matches****', , if follow error find '****matches***' in front of listview , spinner in hierarchy.

in order solve problem have multiple adapter views, can call viewmatchers.inadapterview():

ondata(isfooter()).inadapterview(withid(r.id.list)).perform(click()); 

and done.


Comments