Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Espresso: click() on a TextView

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()));
}
like image 527
swalkner Avatar asked Mar 09 '26 00:03

swalkner


1 Answers

try this :

onView(withText(R.string.letter_personal_data)).check(matches(notNullValue()));
    onView(withText(R.string.letter_personal_data)).perform(click());
like image 116
ganjarpm Avatar answered Mar 10 '26 14:03

ganjarpm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!