Reputation: 17329
I do have a TextView with an onClick-method defined in xml. In the app everything works fine and as expected, but I don't get it to work via Espresso.
I try
onView(withId(R.id.my_text_view)).perform(click());
but the according method is never executed. How can I achieve this?
this is my TextView:
<TextView
android:id="@+id/letter_personal_data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:background="@drawable/letter_border_background"
android:focusable="true"
android:focusableInTouchMode="true"
android:clickable="true"
android:onClick="showPersonalDataDialog"
android:padding="@dimen/letter_standard_padding"
android:text="@string/letter_personal_data"
android:textAppearance="@style/LetterTextOrange"
android:textStyle="bold" />
and this is how my test looks like:
@Test
public void myFirstTest() {
onView(withId(R.id.letter_personal_data)).check(matches(notNullValue()));
onView(withId(R.id.letter_personal_data)).perform(click());
onView(withId(R.id.personal_data_name_text)).check(matches(notNullValue()));
}
Upvotes: 3
Views: 2848
Reputation: 11
try this :
onView(withText(R.string.letter_personal_data)).check(matches(notNullValue()));
onView(withText(R.string.letter_personal_data)).perform(click());
Upvotes: 1