Issue
I have a custom view on which I need to call a specific method to open an activity. What is the right way to do this in an Espresso test?
Do I just need to inflate this view or do I need to write a custom ViewAction
?
Solution
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());
Answered By - lelloman
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.