Prabin Timsina Prabin Timsina - 6 months ago 159
Java Question

Espresso Android matching textviews inside parent

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

Answer

Use hasDescendant()

onView(withId(R.id.recycler_view)).check(matches(atPosition(0, hasDescendant(withText("Available")))));
Comments