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
Try this below logic
// Check if it is displayed
onData(PreferenceMatchers.withKey(context.getResources().getString(R.string.prefkey))).check(matches(isDisplayed()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With