I'm hoping some could help shed some light custom view machers for me. I ran the Record Espresso Test and android-studio generated the following code.
ViewInteraction textInputEditText = onView(
allOf(withId(R.id.edit_text_last_name),
childAtPosition(
allOf(withId(R.id.layout_item_viewpager),
childAtPosition(
withId(R.id.layout_my_activity),
0)),
1),
isDisplayed()));
textInputEditText.perform(replaceText("a"), closeSoftKeyboard());
}
private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
The code generated by Record Espresso Test works, I'm not sure how the child views work or what the 0 and 1 do in this code block.
I've read a fair amount of information on Hamcrest matchers and how to creat custom Matchers but I'm having a hard time finding material that relates to the android generated code. Any help here would be greatly appreciated.