2

I am trying to run an espresso test using onData and everything works fine for a view that has only one AdapterView inside of it. However, when the screen shows a view that has multiple adapter views nested in it, I get:

android.support.test.espresso.AmbiguousViewMatcherException: 'is assignable from class: class android.widget.AdapterView' matches multiple views in the hierarchy.

Is there any way to specify which adapter view onData should be looking at?

JJD
  • 50,076
  • 60
  • 203
  • 339
mikesol
  • 1,177
  • 1
  • 11
  • 20

1 Answers1

1

For the sake of the answer, let's assume that one of your adapterviews is an ExpandableListView and the other is a ListView and that they can be easily identified by their unique id in the layout file.

All you need to do is use the isDescendentOfA matcher to isolate your desired AdapterView like so:

onData(...).
inAdapterView(allOf(
    isAssignableFrom(AdapterView.class),
    isDescendantOfA(withId(R.id.listView))))

However, if your adapter views don't have different ids, just look through their various attributes, and you may find uniquely identifiable properties against which you can narrow down your selection.

JJD
  • 50,076
  • 60
  • 203
  • 339
appoll
  • 2,910
  • 28
  • 40