2016-03-05 116 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())); 
相关问题