hamcrest - Android - espresso - clicking on a listview entry based on custom objects -


espresso used automatic testing app.

edit: below find number of answers!

how can click (within automated espresso test script) on entry in long list of custom objects?

in espresso documentation there example of longlist. working list of objects do. trying many options step map object didn't yield results far.

the espresso documentation says 'ondata' should used. so, like:

ondata( myobjecthascontent("my_item: 50")).perform(click()); onview(withid( r.id.selection_pos2)).check(matches(withtext("50"))); 

my questions (and think helpful learning community): - can write matcher this? - how can use in 'ondata' ?

what situation? on screen have listview of objects like:

public class myojbect {      public string content;      public int    size;  } 

the adapter use populate populated list is:

public class myobjectwithitemandsizeadapter extends arrayadapter<myobjectwithitemandsize> {     private final context context;     private final list<myobjectwithitemandsize> values;     ...     @override     public view getview(int position, view concertview, viewgroup parent) {         view view = null;         if (concertview != null) {             view = (linearlayout) concertview;         } else {             layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);             view = inflater.inflate( r.layout.list_item, parent, false);         }          textview itemt = (textview) view.findviewbyid( r.id.item_content);         itemt.settext( values.get(position).item);         textview sizet = (textview) view.findviewbyid( r.id.item_size);         sizet.settext( "" + values.get(position).size);         return view;     }  } 

the matcher given ondata() must match desired value returned adapter.getitem(int) of desired listview.

so in example, matcher should this:

public static matcher<object> withcontent(final string content) {     return new boundedmatcher<object, myobjectwithitemandsize>(myobjectwithitemandsize.class) {         @override         public boolean matchessafely(myobjectwithitemandsize myobj) {             return myobj.content.equals(content);         }          @override         public void describeto(description description) {             description.appendtext("with content '" + content + "'");         }     }; } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -