Dear community,
How can we use espresso onView and execute in the “Settings” activity, which contains the PreferenceFragment as follows: http://developer.android.com/guide/topics/ui/settings.html#Fragment
The settings are listed, so you need to request specific preferences as follows:
// 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 useful: 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()));