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

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -