How can we use espresso onView and perform in a Settings activity that contains a PreferenceFragment like this: http://developer.android.com/guide/topics/ui/settings.html#Fragment
How can we use espresso onView and perform in a Settings activity that contains a PreferenceFragment like this: http://developer.android.com/guide/topics/ui/settings.html#Fragment
The Preferences are in a list so you have to query for the specific preference like this:
// 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());
I found this article helpful: http://www.winters.nz/2015/05/espresso-for-android-hints-properties.html