Android Espresso - How to check EditText hint?
Looks like I figured it out. Basically, you need to create your own matcher:
public static Matcher<View> withHint(final String expectedHint) {
return new TypeSafeMatcher<View>() {
@Override
public boolean matchesSafely(View view) {
if (!(view instanceof EditText)) {
return false;
}
String hint = ((EditText) view).getHint().toString();
return expectedHint.equals(hint);
}
@Override
public void describeTo(Description description) {
}
};
}
Then you can use it:
onView(withId(R.id.locationInput)).check(matches(withHint("Location (Optional)")));
Since Espresso 2.0 just use internal ViewMatcher withHint:
onView(withId(R.id.locationInput)).check(matches(withHint("your_hint")))