2016-03-05 113 views

回答

1

的偏好在一個列表,所以你必須查詢具體的偏好是這樣的:

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

1

請嘗試以下邏輯

// Check if it is displayed  
onData(PreferenceMatchers.withKey(context.getResources().getString(R.string.prefkey))).check(matches(isDisplayed())); 
相關問題