I have a view hierarchy like below:
GridView{id=2131362110, res-name=item_list_grid,
|
+----->RelativeLayout{id=2131362124, res-name=item_image_thumb_layout
|
+------------->ImageView{id=2131362125, res-name=item_image
|
+----->RelativeLayout{id=2131362124, res-name=item_image_thumb_layout
|
+------------->ImageView{id=2131362125, res-name=item_image
|
+------>RelativeLayout{id=2131362124, res-name=item_image_thumb_layout
|
+------------->ImageView{id=2131362125, res-name=item_image
|
GridView{id=2131362110, res-name=item_list_grid, ...etc
I want to perfom click on one of the ImageView with id=item_image.
I can not use something like atPosition(x) together with onView so instead I used onData. I tried all of these:
onData(allOf(anything(),withId(R.id.item_image))).atPosition(0).perform(click());
onData(anything()).atPosition(0).perform(click());
onData(allOf(atPosition(0),withId(R.id.item_image))).perform(click());
But all resulted in
android.support.test.espresso.AmbiguousViewMatcherException: 'is assignable from class: class android.widget.AdapterView' matches multiple views in the hierarchy.
Any suggestions for this? Thanks!
Your error message tell you have multiple views in your activity that extends form AdapterView
so you have another ListView
or GridView
in your layout.
You can either select the AdapterView
on the data layer. So select this AdapterView
with items of type ItemModel
onData(is(instanceOf(ItemModel.class))).atPosition(0)
.onChildView(withId(R.id.item_image)).perform(click());
or you can choose a specific AdapterView
by id
onData(anything()).inAdapterView(withId(R.id.my_grid_view)).atPosition(0).
onChildView(withId(R.id.item_image)).perform(click());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With