本文介绍了Android Espresso.如何在TextInputLayout中检查ErrorText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我试图测试登录不正确后在电子邮件字段中显示的错误.
Basically I am trying to test that after login incorrectly I have an error showing in the email field.
视图是:
<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一起使用:
This works with a 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) {
}
};
}
这篇关于Android Espresso.如何在TextInputLayout中检查ErrorText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!