[英]How can we use espresso to test an android settings activity with an PreferenceFragment?
我們如何使用 espresso onView並在包含 PreferenceFragment 的設置活動中執行,如下所示: http : //developer.android.com/guide/topics/ui/settings.html#Fragment
首選項位於列表中,因此您必須像這樣查詢特定首選項:
// Check if is displayed
onData(allOf(is(instanceOf(Preference.class)), withKey("prefkey"))).check(matches(isDisplayed()));
// Perform click
onData(allOf(is(instanceOf(Preference.class)), withKey("prefkey"))).onChildView(withClassName(is(Switch.class.getName()))).perform(click());
我發現這篇文章很有幫助: http : //www.winters.nz/2015/05/espresso-for-android-hints-properties.html
試試這個下面的邏輯
// Check if it is displayed
onData(PreferenceMatchers.withKey(context.getResources().getString(R.string.prefkey))).check(matches(isDisplayed()));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.