基本上我正在尝试测试在错误登录后我在电子邮件字段中显示错误。
观点是:
<android.support.design.widget.TextInputLayout
android:id="@+id/ti_email"
android:paddingEnd="10dp"
android:paddingTop="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingStart="10dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/et_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/authentication_email_placeholder"
android:inputType="textEmailAddress"
android:maxLines="1"
android:textSize="16sp"
tools:text="@string/placeholder_email"/>
</android.support.design.widget.TextInputLayout>
我试着这样做:
onView(withId(R.id.et_email))
.check(matches(hasErrorText(
ctx.getString(R.string.authentication_error_empty_email))));
最佳答案
这适用于 CustomMatcher:
public static Matcher<View> hasTextInputLayoutErrorText(final String expectedErrorText) {
return new TypeSafeMatcher<View>() {
@Override
public boolean matchesSafely(View view) {
if (!(view instanceof TextInputLayout)) {
return false;
}
CharSequence error = ((TextInputLayout) view).getError();
if (error == null) {
return false;
}
String hint = error.toString();
return expectedErrorText.equals(hint);
}
@Override
public void describeTo(Description description) {
}
};
}
关于安卓 Espresso 。如何检查 TextInputLayout 中的 ErrorText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34285782/