0

I am setting up UI Tests and keep getting an androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching:error message

My xml file looks like this with multiple categories

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
                  android:key="@string/key_preference_screen"
                  android:title="@string/sometitlename">
    <PreferenceCategory
        android:layout="@layout/category_layout"
        android:key="@string/key_pref_">
        <Preference
            android:key="@string/key"
            android:title="@string/pref_title"/>
    </PreferenceCategory>
</PreferenceScreen>

I've tried variations of

onData(allOf(`is`(instanceOf(Preference::class.java)),
                 withKey(R.string.key),             
                 withTitle(R.string.pref_title)))
                .onChildView(withText(pref_title))
                .check(matches(isCompletelyDisplayed()))```

1 Answers1

0

Preference Matcher uses Recyclerview internally.Referenced from here

onView(withId(androidx.preference.R.id.recycler_view))
    .perform(
      RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>(
        1,
        click()
      ))
Veena
  • 869
  • 1
  • 7
  • 22