android - Espresso onData perform click on multiple items -
i have gridview adapter based on list of pojos of type tile minesweeper game, im doing unit tests , want click on gridview items dont have mines , longclick items have items
i have tried following:
ondata(allof(is(instanceof(tile.class)),isminematcher(true))) .inadapterview(withid(r.id.f_minefield_gridview)) .perform(longclick()); ondata(allof(is(instanceof(tile.class)),isminematcher(false))) .inadapterview(withid(r.id.f_minefield_gridview)) .perform(click());
with custom matcher:
public static matcher<tile> isminematcher(final boolean flag){ return new typesafematcher<tile>() { @override public boolean matchessafely(tile tile) { return tile.ismine() == flag; } @override public void describeto(description description) { description.appendtext("expected "+ flag); } }; }
but presents following error:
android.support.test.espresso.performexception: error performing 'load adapter data' on view 'with id: com.kaissersoft.minesweepergame:id/f_minefield_gridview'. ... caused by: java.lang.runtimeexception: multiple data elements matched:
the question how perform actions on multiple items espresso?
why don't try given in testdroid. worked me:
if have other objects in adapter:
public class person { public long id; public string firstname; public string lastname; public string email; }
you can use ondata :
ondata(allof(is(new boundedmatcher<object, person>(person.class) { @override public void describeto(description description) { } @override protected boolean matchessafely(person obj) { return obj.id = 12345l; } }))).inadapterview(withid(<adapter_id>)).perform(click());
so person id=12345 found in adapter (during test execution) , clicked.
check out detailed explanation here