作者:手机用户2602931923_450 | 来源:互联网 | 2023-05-22 19:08
我有password.setError(getResources().getString(R.string.incorrect_data));
如果我设置无效密码 - 显示带有文本"无效数据!"的textView,我需要通过Espresso进行测试,我写道:
onView(withText(R.string.incorrect_data)).check(matches(isDisplayed()));
但这是错的,我有:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with string from resource id: <2131493034>[incorrect_data] value: Invalid data!
If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:android.widget.ListView{307b4f3a IFED.VC. ......ID -480,0-0,1022 #7f0a004c app:id/left_drawer}
如果我写: onView(withText("Invalid data!")).check(matches(isDisplayed()));
我有:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with text: is "Invalid data!"
If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:android.widget.ListView{307b4f3a IFED.VC. ......ID -480,0-0,1022 #7f0a004c app:id/left_drawer}
我用浓咖啡2:
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static android.support.test.espresso.Espresso.onView;
请帮帮我.
1> Paushchyk Ju..:
帮助过我:
onView(withId(R.id.password)).check(matches(withError(
getActivity().getString(R.string.incorrect_data))));
private static Matcher withError(final String expected) {
return new TypeSafeMatcher() {
@Override
public boolean matchesSafely(View view) {
if (!(view instanceof EditText)) {
return false;
}
EditText editText = (EditText) view;
return editText.getError().toString().equals(expected);
}
@Override
public void describeTo(Description description) {
}
};
}