Check for espresso text message on Android in the EditText editor?

I know how to check if error text is set in EditText :

 editText.check(matches(hasErrorText(""))); 

Now I want to check if the error text is set by EditText . I tried this, but it does not work.

 editText.check((matches(not(hasErrorText(""))))); 

Does anyone know how to do this? Thanks!

+5
source share
1 answer

I don't think this is possible, depending on what you want exactly, I would use a custom socket:

 public static Matcher<View> hasNoErrorText() { return new BoundedMatcher<View, EditText>(EditText.class) { @Override public void describeTo(Description description) { description.appendText("has no error text: "); } @Override protected boolean matchesSafely(EditText view) { return view.getError() == null; } }; } 

This mate can check for errors in the TextText editor, use it as follows:

 onView(allOf(withId(R.id.edittext), isDisplayed())).check(matches(hasNoErrorText())); 
+7
source

Source: https://habr.com/ru/post/1265176/


All Articles