Search code examples
androidandroid-edittextandroid-espressotextcolor

Test with espresso with "hasTextColor"


How can I make a espresso test with the color of the text? Currently use hasTextColor():

onView(withId(R.id.editText)).check(matches(hasTextColor(Color.BLACK)));

But the error occurs:

android.content.res.Resources$NotFoundException: Resource ID #0xff000000 at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:195)

...

Details:

<EditText
 android:id="@+id/editText"
 android:textColor="#ff000000"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_marginTop="48dp"/>

Solution

  • You need to check against a color defined in the resources like hasTextColor(R.color.red)

    It's also written in the documentation link you provided: colorResId : int