samedi 22 octobre 2016

Android Espresso: unable to find checkbox with unique android:id

I am trying to test a checkbox on a PreferenceScreen.

The PreferenceScreen contains two CheckBoxPreferences, each with unique android:id.

    <CheckBoxPreference
        android:id="@+id/first_checkbox"
        android:key="first_checkbox"
        android:title="First checkbox" />

    <CheckBoxPreference
        android:id="@+id/second_checkbox"
        android:key="second_checkbox"
        android:title="Second checkbox" />

Here are the id values from R.java file:

public static final class id {
    public static final int first_checkbox=0x7f0a0000;
    public static final int second_checkbox=0x7f0a0001;
}

On my test:

    ViewInteraction cbxFirst = onView(withId(R.id.first_checkbox));

I see:

    NoMatchingViewException: No views in  hierarchy found matching: with id:  
    com.test.fragmentpreference:id/first_checkbox

When I try to search by 'android.R.id.checkbox' instead of 'R.id.first_checkbox':

    ViewInteraction cbxFirst = onView(withId(android.R.id.checkbox));

I receive:

    AmbiguousViewMatcherException: 'with id: android:id/checkbox' matches multiple views in the hierarchy.

My question is: How can I test the first checkbox using 'first_checkbox' id ?




Aucun commentaire:

Enregistrer un commentaire