Espresso:单击具有相同Id的许多文本视图中的一个

时间:2016-07-28 07:51:13

标签: android automated-tests android-espresso

如何使用相同的ID从不同的文本视图中单击单个文本视图。这些是线性布局的子项。它们具有动态给出的文本,如A,B,C,D,具有id txt_option_index的textview。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:clickable="true"
android:id="@+id/option_rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/border">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="@dimen/topMarginU2"
android:layout_centerVertical="true"
android:id="@+id/option_sign_bg_rl">
<TextView
android:id="@+id/txt_option_index"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="@drawable/circle_shape_white_answer"
android:gravity="center"
android:text="A"
android:textColor="@color/black"
android:textSize="10dp" />
</RelativeLayout>
<TextView
android:id="@+id/optiontext"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/topMarginU2"
android:layout_marginBottom="@dimen/topMarginU2"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/option_sign_bg_rl"
android:text="option one found"
android:layout_marginLeft="@dimen/topMarginU2"
android:clickable="true"
android:singleLine="false"
style="@style/txt_14_light_hex_grey_Text" />
</RelativeLayout>

我试过了:

ViewInteraction relativeLayout = onView(allOf(withId(R.id.txt_option_index),
withParent(withId(R.id.option_sign_bg_rl)),withText("B")));
relativeLayout.perform(scrollTo(), click());

ViewInteraction rr = onView(allOf(withId(R.id.txt_option_index),withText("A")));    rr.perform(click());

onView(allOf(withId(R.id.txt_option_index),hasSibling(withText("A")))).perform(click());

但没有运气, 错误

android.support.test.espresso.AmbiguousViewMatcherException

0 个答案:

没有答案