1

I have an LinearLayout, in which I add and remove view programmatically. But I add not a particularly view, instead I add ConstraintLayout with other view, that I need to test. So here in ConstaintLayout places EditText, which I want to test, type and check values, rest EditText. But I don't know how to get EditText with Espresso. I supposed that should work like this:

@Test
fun basicConverting() {
    onView(
        allOf(
            withParent(withId(R.id.convertingViewList)),
            withParentIndex(0),
            withParent(withId(R.id.convertingView)),
            withParentIndex(1)
        )
    ).perform(typeText("12"))
}

But I get an error:

androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (view.getParent() view.getId() is <2131296372/com.human_developing_soft.unitconverter:id/convertingViewList> and (view.getParent() is an instance of android.view.ViewGroup and is at child index <0>) and view.getParent() view.getId() is <2131296684/com.human_developing_soft.unitconverter:id/convertingView> and (view.getParent() is an instance of android.view.ViewGroup and is at child index <1>)) If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:androidx.appcompat.widget.AppCompatSpinner{8f3246f VFED..CL. ........ 597,45-1035,113 #7f09019c app:id/unit_first_selector}

Please, help solve it. Thanks in advance!

  • Can you show your actual view hierarchy? My assumption is that the view doesn't match your specified matcher. – agoff Aug 09 '21 at 13:31
  • Without the view hierarchy we can't really help you. But I will say that the matchers you have are conflicting. You can't have a view with a parent that has 2 IDs and 2 indexes. – Just The Highlights Aug 19 '21 at 21:48

0 Answers0