问题
So here's a breakdown of my hierarchy:
RecyclerView --> LinearLayout --> RecyclerView --> FrameLayout -> FrameLayout
Here's a screenshot:
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.
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/34138945/espresso-matcher-for-nested-recyclerview