android - Accessing a RadioButton and selecting it in Espresso -


i using espresso test android application. having trouble trying find way access , select radiobutton (which belongs radiogroup) of current activity. have suggestions? you

-andrew

given following layout:

<radiogroup         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:id="@+id/radiogroup"         >          <radiobutton             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="@string/first_radio_button"             android:id="@+id/firstradiobutton"             />          <radiobutton             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="@string/second_radio_button"             android:id="@+id/secondradiobutton"             />          <radiobutton             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="@string/third_radio_button"             android:id="@+id/thirdradiobutton"             />      </radiogroup> 

write new test method following:

        onview(withid(r.id.firstradiobutton))                 .perform(click());          onview(withid(r.id.firstradiobutton))                 .check(matches(ischecked()));          onview(withid(r.id.secondradiobutton))                 .check(matches(not(ischecked())));          onview(withid(r.id.thirdradiobutton))                 .check(matches(not(ischecked()))); 

voila!


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -