Multiple match problem in recycler view appear when there are multiple buttons having the same id but you are clicking on the particular button so the point is first you have to go in recycler view then at that particular position we have to perform the click.
Error:-
1 |
android.support.test.espresso.AmbiguousViewMatcherException: 'Problem views are marked with '****MATCHES****' below. |
Solution :-
1 |
MyViewAction myViewAction = new MyViewAction(); |
Here we have class “MyViewAction” with object “myViewAction“.
Then we using this class in code like this:-
1 2 |
onView(withId(R.id.my_recycler_view)).perform( RecyclerViewActions.actionOnItemAtPosition(0, MyViewAction.clickChildViewWithId(R.id.buttonid))); |
here “my_recycler_view” is the id of recycler view and “0” is the position where we want to click that button and “
button-id” is the id of the button on which we have to perform the click.
Here is the class “MyViewAction“:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
public static class MyViewAction { public static ViewAction clickChildViewWithId(final int id) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return null; } @Override public String getDescription() { return "Click on a child view with specified id."; } @Override public void perform(UiController uiController, View view) { View v = view.findViewById(id); v.performClick(); } }; } } |
By using this technique you can easily locate to your location When there are multiple same id buttons.
In next blog, we will discuss more basics, errors with solutions of espresso scripts.