I have started using Espresso for automating my tests and the problem I face is, am not able to match the exact textview from my xml file.
Sample xml be like:
xmlns:app="http://schemas.xx.com/apk/res-auto"
android:id="@+id/filter_sort_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="2dp">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_marginEnd="10dp"
android:layout_marginStart="10dp"
android:animateLayoutChanges="true"
android:shrinkColumns="0">
<TableRow>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/dropdown_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:clickable="true"
android:ellipsize="end"
android:focusable="true"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingBottom="15dp"
android:paddingEnd="5dp"
android:paddingTop="15dp"
android:textColor="@color/colorAccent" />
<android.support.v7.widget.AppCompatImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="3dp"
app:srcCompat="@drawable/ic_triangle" />
</LinearLayout>
Am trying to check whether the id 'dropdown_title' is present and have to get the text from it. Code I used:
onView(allOf(
withId(R.id.dropdown_title),
withParent(withId(R.id.filter_sort_layout)))).
check(matches(isDisplayed();
But, it throws me error saying,
'android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (with id: xx.debug:id/dropdown_title and has parent matching: with id: xx/filter_sort_layout)
View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=1080, height=1920, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}
|
+->LinearLayout{id=-1, visibility=VISIBLE, width=1080, height=1776, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+-->ViewStub{id=16909227, res-name=action_mode_bar_stub, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
+-->FrameLayout{id=-1, visibility=VISIBLE, width=1080, height=1704, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=72.0, child-count=1}
|
+--->FitWindowsLinearLayout{id=2131820663, res-name=action_bar_root, visibility=VISIBLE, width=1080, height=1704, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|'
I have tried using descendantOfA()
and also hasSibling()
methods. Doesn't work. Please help me out.