Reputation: 2182
I have a simple linear layout with two textviews inside it. The linear layout has an unique id but the textviews don't have. How do I verify one of the texts is from those textviews?
I tried the following code:
onView(allOf(NavigationDrawerComponent.topSectionWrapper,
hasSibling(withClassName(Matchers.equalTo(TextView.class.getSimpleName())))))
.check(matches(withText(Data.fullUserName)));
Unfortunately,its not working for me.I am getting the following error:
android.support.test.espresso.NoMatchingViewException: No views in
hierarchy found matching
Upvotes: 4
Views: 3592
Reputation: 1636
Sometimes you may want to scroll the RecyclerView
until you find the right child view (if the view is not visible, it is probably not yet created). In that case using scrollTo
is not enough and Android Studio will not recommend a better choice automatically. You have to do this:
onView(withId(R.id.recycler_view))
.perform(RecyclerViewActions.scrollTo(hasDescendant(withText("Available"))));
Upvotes: 0
Reputation: 2182
Use hasDescendant()
onView(withId(R.id.recycler_view)).check(matches(atPosition(0, hasDescendant(withText("Available")))));
Upvotes: 4