android - (Robotium) How to select a RadioButton in a RadioGroup -


in android app view layout, have <radiogroup> contains 2 <radiobutton>:

<radiogroup      android:id="@+id/my_radio_group"      android:layout_width="wrap_content"      android:layout_height="wrap_content"      android:orientation="vertical">        <radiobutton         android:id="@+id/yes_btn"         android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/yes"       />       <radiobutton        android:id="@+id/no_btn"          android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:text="@string/no"       /> </radiogroup> 

i use robotium library write junit test radio group to selection 1 radio button. test code snippet is:

solo solo = new solo(getinstrumentation(), getactivity());  ... solo.clickonradiobutton(r.id.yes_btn); //i expect "yes" radio button selected 

i expected above test code select "yes" radio button, when run it, raise error:

junit.framework.assertionfailederror: 2131427675 radiobuttons not found! @ com.jayway.android.robotium.solo.waiter.waitforandgetview(waiter.java:417) @ com.jayway.android.robotium.solo.clicker.clickon(clicker.java:374) @ com.jayway.android.robotium.solo.solo.clickonradiobutton(solo.java:1063) ... 

how can select 1 <radiobutton> in <radiogroup> robotium??

try below code

radiobutton rb = (radiobutton) solo.getview(r.id.yes_btn); solo.clickonview(rb); 

solo.clickonradiobutton() takes view index argument, while passing resource id.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -