如何进行UI测试首选项片段

问题描述 投票:0回答:1

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

我的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()))```
<<

Preference Matcher内部使用Recyclerview。参考here
onView(withId(androidx.preference.R.id.recycler_view)) .perform( RecyclerViewActions.actionOnItemAtPosition<RecyclerView.ViewHolder>( 1, click() ))
android kotlin android-espresso ui-testing
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.