Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso Matcher for Nested RecyclerView

So here's a breakdown of my hierarchy:

RecyclerView --> LinearLayout --> RecyclerView --> FrameLayout -> FrameLayout 

Here's a screenshot:

layout

I would like to be able to verify the FrameLayout with the text is displayed. This what I have tried so far:

onView(withRecyclerView(R.id.container_list).atPositionOnView(0, R.id.row_content))
                .check(matches(withRecyclerView(R.id.row_content).atPositionOnView(0, R.id.info_field)))
                .check(matches(isDisplayed()));

But it causes an AmbiguousViewMatcherException. Any ideas on how to verify that nested view? Should mention I'm using the ViewMatcher from here. Thanks.

like image 497
brwngrldev Avatar asked Dec 07 '15 16:12

brwngrldev


2 Answers

I was able to verify it using the explanation @manidesto provided above with some slight changes.

onView(allOf(isDescendantOfA(withRecyclerView(R.id.container_list).atPosition(0)),
                isDescendantOfA(withRecyclerView(R.id.row_content).atPosition(0)),
                withId(R.id.info_field)))
                .check(matches(isDisplayed()));

Main enhancement is I used the allOf matcher to specify multiple characteristics of the view I was trying to verify.

like image 120
brwngrldev Avatar answered Oct 22 '22 04:10

brwngrldev


Try this

onView(withRecyclerView(R.id.container_list).atPositionOnView(0, R.id.row_content))
    .check(matches(withChild(withId(R.id.info_field))))

This just checks whether the View(R.id.row_content) has a child with id R.id.info_field

Note:

.check() takes in a ViewAssertion which means that the view matched by your ViewMatcher given to the onView() method is just asserted by the ViewAssertion

So when you do

onView(withRecyclerView(R.id.container_list).atPositionOnView(0, R.id.row_content))
    .check(matches(withChild(withId(R.id.info_field))))
    .check(matches(isDisplayed()))

the ViewMatcher - isDisplayed() is applied to R.id.row_content matched inside onView() not the R.id.info_field asserted to matching in .check() call

like image 31
okmanideep Avatar answered Oct 22 '22 04:10

okmanideep