【问题标题】:How to UI test Preference Fragment如何 UI 测试偏好片段
【发布时间】:2019-08-14 23:49:20
【问题描述】:

我正在设置 UI 测试并不断收到 androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching:error 消息

我的 xml 文件看起来像这样,有多个类别

<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>

我尝试了各种变化

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

【问题讨论】:

    标签: android kotlin android-espresso ui-testing


    【解决方案1】:

    Preference Matcher 在内部使用 Recyclerview。引用自 here

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-29
      • 1970-01-01
      • 2019-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多