在居preSSO访问一个单选按钮,然后选择它 [英] Accessing a RadioButton and selecting it in Espresso
本文介绍了在居preSSO访问一个单选按钮,然后选择它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的长者preSSO来测试Android应用程序。我有麻烦试图找到一种方式,当前活动的访问,并选择一个单选按钮(这属于RadioGroup中)。有没有人有什么建议?
感谢您
I am using Espresso to test an Android application. I am having trouble trying to find a way to access and select a RadioButton (which belongs to a RadioGroup) of the current Activity. Does anyone have any suggestions? Thanks you
-Andrew
推荐答案
由于以下布局:
<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 a new test method with the 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())));
瞧!
这篇关于在居preSSO访问一个单选按钮,然后选择它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文