我是 UI 測驗的新手,尤其是使用 Espresso。在我的用例中,我需要檢查應用程式是否接受片段EditTextPreference內的輸入文本PreferenceScreen,但在此之前我需要執行單擊以顯示編輯對話框,然后輸入文本。
這是首選項片段具有編輯小部件的方式:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<EditTextPreference
android:key="@string/pref_stream_target_key"
android:title="@string/pref_stream_target_label"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
android:key="@string/pref_stream_resolution_key"
android:title="@string/pref_stream_resolution_label"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
android:key="@string/pref_stream_bitrate_key"
android:title="@string/pref_stream_bitrate_label"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
android:key="@string/pref_stream_framerate_key"
android:title="@string/pref_stream_framerate_label"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
android:key="@string/pref_stream_peerlatency_key"
android:title="@string/pref_stream_peerlatency_label"
app:useSimpleSummaryProvider="true" />
</PreferenceScreen>
這就是我嘗試執行點擊的方式
with(launchFragmentInContainer<StreamSettingsFragment>()) {
onFragment { fragment ->
Espresso.onData(PreferenceMatchers.withTitle(R.string.pref_stream_target_label))
.perform(ViewActions.click())
}
}
我不確定是否需要進行單擊操作以檢查EditTextPreference.
用這個運行測驗只會讓應用程式運行,什么都不做。有什么我想念的嗎?
編輯:讓 espresso 作業而不做任何事情的解決方案是將代碼從onFragment塊中取出,但是我仍然無法對EditTextPreference小部件執行操作。
這是被拋出的錯誤:
androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: is assignable from class <class android.widget.AdapterView>
View Hierarchy:
>DecorView{id=-1, visibility=VISIBLE, width=1080, height=2218, has-focus=false, 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, layout-params={(0,0)(fillxfill) ty=BASE_APPLICATION hwFlags=#10 isEmuiStyle=0 statusBarColor=#ff000000 navigationBarColor=#fffcfcfc wanim=0x1030001
fl=LAYOUT_IN_SCREEN LAYOUT_INSET_DECOR SPLIT_TOUCH HARDWARE_ACCELERATED}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
->ActionBarOverlayLayout{id=16908903, res-name=decor_content_parent, visibility=VISIBLE, width=1080, height=2218, has-focus=false, 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, layout-params=android.widget.FrameLayout$LayoutParams@aa563f7, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}
|
-->FrameLayout{id=16908290, res-name=content, visibility=VISIBLE, width=1080, height=1966, has-focus=false, 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, layout-params=com.android.internal.widget.ActionBarOverlayLayout$LayoutParams@4eb0264, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=252.0, child-count=1}
|
--->LinearLayout{id=-1, visibility=VISIBLE, width=1080, height=1966, has-focus=false, 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, layout-params=android.widget.FrameLayout$LayoutParams@2f83982, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
---->FrameLayout{id=16908351, res-name=list_container, visibility=VISIBLE, width=1080, height=1966, has-focus=false, 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, layout-params=android.widget.LinearLayout$LayoutParams@1c24893, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
----->RecyclerView{id=2131296596, res-name=recycler_view, visibility=VISIBLE, width=1080, height=1966, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@687e0d0, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=5}
|
------>LinearLayout{id=0, visibility=VISIBLE, width=1080, height=241, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=androidx.recyclerview.widget.RecyclerView$LayoutParams@2746bce, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}
|
------->LinearLayout{id=2131296469, res-name=icon_frame, visibility=INVISIBLE, width=168, height=24, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@3bedaef, tag=null, root-is-layout-requested=false, has-input-connection=false, x=18.0, y=108.0, child-count=1}
|
-------->PreferenceImageView{id=16908294, res-name=icon, visibility=INVISIBLE, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@2d239fc, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=12.0}
|
------->RelativeLayout{id=-1, visibility=VISIBLE, width=876, height=241, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@615a885, tag=null, root-is-layout-requested=false, has-input-connection=false, x=186.0, y=0.0, child-count=2}
|
-------->TextView{id=16908310, res-name=title, visibility=VISIBLE, width=400, height=88, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@c6f76da, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=48.0, text=Stream target, input-type=0, ime-target=false, has-links=false}
|
-------->TextView{id=16908304, res-name=summary, visibility=VISIBLE, width=136, height=57, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@848370b, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=136.0, text=Not set, input-type=0, ime-target=false, has-links=false}
|
------->LinearLayout{id=16908312, res-name=widget_frame, 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, layout-params=android.widget.LinearLayout$LayoutParams@506f9e8, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
|
------>LinearLayout{id=0, visibility=VISIBLE, width=1080, height=241, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=androidx.recyclerview.widget.RecyclerView$LayoutParams@ade26a6, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=241.0, child-count=3}
|
------->LinearLayout{id=2131296469, res-name=icon_frame, visibility=INVISIBLE, width=168, height=24, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@ac138e7, tag=null, root-is-layout-requested=false, has-input-connection=false, x=18.0, y=108.0, child-count=1}
|
-------->PreferenceImageView{id=16908294, res-name=icon, visibility=INVISIBLE, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@d45cc94, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=12.0}
|
------->RelativeLayout{id=-1, visibility=VISIBLE, width=876, height=241, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@985633d, tag=null, root-is-layout-requested=false, has-input-connection=false, x=186.0, y=0.0, child-count=2}
|
-------->TextView{id=16908310, res-name=title, visibility=VISIBLE, width=539, height=88, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@360732, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=48.0, text=Stream Resolution, input-type=0, ime-target=false, has-links=false}
|
-------->TextView{id=16908304, res-name=summary, visibility=VISIBLE, width=136, height=57, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@fde7c83, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=136.0, text=Not set, input-type=0, ime-target=false, has-links=false}
|
------->LinearLayout{id=16908312, res-name=widget_frame, 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, layout-params=android.widget.LinearLayout$LayoutParams@bfd1e00, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
|
------>LinearLayout{id=0, visibility=VISIBLE, width=1080, height=241, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=androidx.recyclerview.widget.RecyclerView$LayoutParams@eb9647e, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=482.0, child-count=3}
|
------->LinearLayout{id=2131296469, res-name=icon_frame, visibility=INVISIBLE, width=168, height=24, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@9025ddf, tag=null, root-is-layout-requested=false, has-input-connection=false, x=18.0, y=108.0, child-count=1}
|
-------->PreferenceImageView{id=16908294, res-name=icon, visibility=INVISIBLE, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@8161a2c, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=12.0}
|
------->RelativeLayout{id=-1, visibility=VISIBLE, width=876, height=241, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@76abcf5, tag=null, root-is-layout-requested=false, has-input-connection=false, x=186.0, y=0.0, child-count=2}
|
-------->TextView{id=16908310, res-name=title, visibility=VISIBLE, width=420, height=88, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@8834a8a, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=48.0, text=Stream Bitrate, input-type=0, ime-target=false, has-links=false}
|
-------->TextView{id=16908304, res-name=summary, visibility=VISIBLE, width=136, height=57, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@158f8fb, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=136.0, text=Not set, input-type=0, ime-target=false, has-links=false}
|
------->LinearLayout{id=16908312, res-name=widget_frame, 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, layout-params=android.widget.LinearLayout$LayoutParams@be0ad18, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
|
------>LinearLayout{id=0, visibility=VISIBLE, width=1080, height=241, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=androidx.recyclerview.widget.RecyclerView$LayoutParams@4538556, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=723.0, child-count=3}
|
------->LinearLayout{id=2131296469, res-name=icon_frame, visibility=INVISIBLE, width=168, height=24, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@b429d7, tag=null, root-is-layout-requested=false, has-input-connection=false, x=18.0, y=108.0, child-count=1}
|
-------->PreferenceImageView{id=16908294, res-name=icon, visibility=INVISIBLE, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@4bf82c4, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=12.0}
|
------->RelativeLayout{id=-1, visibility=VISIBLE, width=876, height=241, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@6fa95ad, tag=null, root-is-layout-requested=false, has-input-connection=false, x=186.0, y=0.0, child-count=2}
|
-------->TextView{id=16908310, res-name=title, visibility=VISIBLE, width=514, height=88, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@31aa0e2, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=48.0, text=Stream framerate, input-type=0, ime-target=false, has-links=false}
|
-------->TextView{id=16908304, res-name=summary, visibility=VISIBLE, width=136, height=57, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@278c73, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=136.0, text=Not set, input-type=0, ime-target=false, has-links=false}
|
------->LinearLayout{id=16908312, res-name=widget_frame, 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, layout-params=android.widget.LinearLayout$LayoutParams@1940730, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
|
------>LinearLayout{id=0, visibility=VISIBLE, width=1080, height=241, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=androidx.recyclerview.widget.RecyclerView$LayoutParams@245e92e, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=964.0, child-count=3}
|
------->LinearLayout{id=2131296469, res-name=icon_frame, visibility=INVISIBLE, width=168, height=24, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@c647ccf, tag=null, root-is-layout-requested=false, has-input-connection=false, x=18.0, y=108.0, child-count=1}
|
-------->PreferenceImageView{id=16908294, res-name=icon, visibility=INVISIBLE, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@bea665c, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=12.0}
|
------->RelativeLayout{id=-1, visibility=VISIBLE, width=876, height=241, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@525cd65, tag=null, root-is-layout-requested=false, has-input-connection=false, x=186.0, y=0.0, child-count=2}
|
-------->TextView{id=16908310, res-name=title, visibility=VISIBLE, width=761, height=88, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@6cb6a3a, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=48.0, text=Stream peer latency (SRT), input-type=0, ime-target=false, has-links=false}
|
-------->TextView{id=16908304, res-name=summary, visibility=VISIBLE, width=136, height=57, 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=false, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@1d616eb, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=136.0, text=Not set, input-type=0, ime-target=false, has-links=false}
|
------->LinearLayout{id=16908312, res-name=widget_frame, 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, layout-params=android.widget.LinearLayout$LayoutParams@7e58c48, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
|
---->TextView{id=16908292, res-name=empty, 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, layout-params=android.widget.LinearLayout$LayoutParams@52adae1, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}
|
-->ActionBarContainer{id=16908719, res-name=action_bar_container, visibility=VISIBLE, width=1080, height=144, 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=false, is-selected=false, layout-params=com.android.internal.widget.ActionBarOverlayLayout$LayoutParams@e7d36c7, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=108.0, child-count=2}
|
--->ActionBarView{id=16908718, res-name=action_bar, visibility=VISIBLE, width=1080, height=144, 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=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@6eb24f4, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
---->LinearLayout{id=-1, visibility=VISIBLE, width=620, height=144, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=false, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.app.ActionBar$LayoutParams@19441d, tag=null, root-is-layout-requested=false, has-input-connection=false, x=24.0, y=0.0, child-count=2}
|
----->HomeView{id=-1, visibility=VISIBLE, width=120, height=144, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@8f10692, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
------>ImageView{id=16909572, res-name=up, 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, layout-params=android.widget.FrameLayout$LayoutParams@58c7863, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0}
|
------>ImageView{id=16908332, res-name=home, visibility=VISIBLE, width=96, height=96, 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=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@90f9c60, tag=null, root-is-layout-requested=false, has-input-connection=false, x=12.0, y=24.0}
|
----->LinearLayout{id=-1, visibility=VISIBLE, width=500, height=73, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@414f9de, tag=null, root-is-layout-requested=false, has-input-connection=false, x=120.0, y=35.0, child-count=2}
|
------>TextView{id=16908722, res-name=action_bar_title, visibility=VISIBLE, width=476, height=73, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@c437bf, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=Genius Live Camera, input-type=0, ime-target=false, has-links=false}
|
------>TextView{id=16908721, res-name=action_bar_subtitle, 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, layout-params=android.widget.LinearLayout$LayoutParams@9421e8c, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}
|
---->ActionMenuView{id=-1, visibility=VISIBLE, 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=false, is-selected=false, layout-params=android.view.ViewGroup$LayoutParams@2bdd9d5, tag=null, root-is-layout-requested=false, has-input-connection=false, x=1080.0, y=72.0, child-count=0}
|
--->ActionBarContextView{id=16908723, res-name=action_context_bar, 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, layout-params=android.widget.FrameLayout$LayoutParams@2f2d5ea, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
|
-->ActionBarContainer{id=16909433, res-name=split_action_bar, 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, layout-params=com.android.internal.widget.ActionBarOverlayLayout$LayoutParams@b8e90db, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}
at dalvik.system.VMStack.getThreadStackTrace(Native Method)
at java.lang.Thread.getStackTrace(Thread.java:1730)
at androidx.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:12)
at androidx.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:7)
at androidx.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:8)
at androidx.test.espresso.ViewInteraction.desugaredPerform(ViewInteraction.java:11)
at androidx.test.espresso.ViewInteraction.perform(ViewInteraction.java:4)
at androidx.test.espresso.DataInteraction$DisplayDataMatcher$1.apply(DataInteraction.java:1)
at androidx.test.espresso.DataInteraction$DisplayDataMatcher$1.apply(DataInteraction.java:2)
at androidx.test.espresso.DataInteraction$DisplayDataMatcher.<init>(DataInteraction.java:7)
at androidx.test.espresso.DataInteraction$DisplayDataMatcher.<init>(DataInteraction.java:13)
at androidx.test.espresso.DataInteraction$DisplayDataMatcher.displayDataMatcher(DataInteraction.java:1)
at androidx.test.espresso.DataInteraction.makeTargetMatcher(DataInteraction.java:2)
at androidx.test.espresso.DataInteraction.perform(DataInteraction.java:1)
at com.domain.division.app.fragment.StreamSettingsFragmentTest.validTarget(StreamSettingsFragmentTest.kt:27)
uj5u.com熱心網友回復:
洗掉該onFragment位 - 這樣您就可以在主執行緒上以同步方式直接與 Fragment 互動。Espresso 被設計為在測驗執行緒上作業并自行處理與 UI 的同步:
launchFragmentInContainer<StreamSettingsFragment>()
onData(withTitle(R.string.pref_stream_target_label)).perform(ViewActions.click())
編輯
好的,現在你明白了No views in hierarchy found matching: is assignable from class <class android.widget.AdapterView> 。這是什么意思?這意味著onData試圖在AdapterView(如 a ListView)中找到一個物件,但沒有找到。
好的,為什么不呢?查看錯誤報告,您將看到:
----->RecyclerView{id=2131296596, res-name=recycler_view, visibility=VISIBLE, width=1080, height=1966, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=android.widget.FrameLayout$LayoutParams@687e0d0, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=5}
|
------>LinearLayout{id=0, visibility=VISIBLE, width=1080, height=241, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, layout-params=androidx.recyclerview.widget.RecyclerView$LayoutParams@2746bce, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}
|
------->LinearLayout{id=2131296469, res-name=icon_frame, visibility=INVISIBLE, width=168, height=24, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@3bedaef, tag=null, root-is-layout-requested=false, has-input-connection=false, x=18.0, y=108.0, child-count=1}
|
-------->PreferenceImageView{id=16908294, res-name=icon, visibility=INVISIBLE, 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=false, is-selected=false, layout-params=android.widget.LinearLayout$LayoutParams@2d239fc, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=12.0}
這是什么意思?這意味著它的專案PreferenceFragment使用了RecyclerViewnot a ListView。因此,PreferenceMatchers并onData不會起作用。
好的,那你怎么辦?對于RecyclerViews您,請改用RecyclerViewActions。
您之前的嘗試可能會轉化為以下內容:
// We know the ID from the error stacktrace you were given
onView(withId(R.id.recycler_view))
.perform(actionOnItem<RecyclerView.ViewHolder>(
// Find the preference that has "target label" text view as a subview
hasDescendant(withText(R.string.pref_stream_target_label)),
click() // And click it
))
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/366549.html
標籤:安卓 测试 android-espresso android-instrumentation
上一篇:使用輔助h2資料庫在SpringBoot中測驗API
下一篇:如何遠程呼叫.py腳本?
