15

I have a custom View class public class Foo extends RelativeLayout{...} which have an EditText in it. The Foo class have a XML layout inflated and its EditText also have an id but its not able to find the EditText

I'm using this Espresso code:

onView(allOf(withId(R.id.edittext), withParent(withId(R.id.name_container)))).check(matches(isDisplayed())).perform(click());

And the error message I get is:

android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (with id: dk.aura.app.staging:id/edittext and has parent matching: with id: dk.aura.app.staging:id/name_container)

1 Answers1

22

With persistence I found an answer to my own question.

It seems that when accessing View inside another View(nested views), you have to check for if it it isDescendantOfA() instead of withParent()

So this is the correct way: onView(allOf(withId(R.id.edittext), isDescendantOfA(withId(R.id.name_container)))).check(matches(isDisplayed()));