android - simple way to convert View to Matcher<View> in espresso -
for ins, following example, hope first set listener , them work espresso, how implement tomatcher
@test public void testspinner2() throws exception { r.launchactivity(null); spinner sp = (spinner) r.getactivity().findviewbyid(r.id.spinner); sp.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { //do smth } }); onview(tomatcher(sp)); }
i guess following code can work:
public static matcher<view> tomatcher(final view v) { return new typesafematcher<view>() { @override protected boolean matchessafely(view item) { return item == v; } @override public void describeto(description description) { description.appendtext(v.tostring()); } }; }
Comments
Post a Comment