How to call a method on a custom view in an Espresso test?
you can create a custom ViewAction like this
public class MyCustomViewAction implements ViewAction{
@Override
public Matcher<View> getConstraints(){
return isAssignableFrom(YourCustomView.class);
}
@Override
public String getDescription(){
return "whatever";
}
@Override
public void perform(UiController uiController, View view){
YourCustomView yourCustomView = (YourCustomView) view;
yourCustomView.yourCustomMethod();
// tadaaa
}
}
and use it as you normally would, like
onView(withId(whatever)).perform(new MyCustomViewAction());