Issue
Hi having issues getting this to work, want to click on login button and test that the validation errors appear. I am using material design validations, this is what I have written
@Test
public void click_login_with_empty_fields_gives_errors() {
onView(withId(R.id.login)).perform(click());
onView(withId(R.id.login_email2)).check(matches(hasErrorText("Email Field cannot be empty")));
onView(withId(R.id.login_password2)).check(matches(hasErrorText("Password field cannot be empty")));
}
The error I get is
androidx.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with error: is "Password field cannot be empty"' doesn't match the selected view.
Expected: with error: is "Password field cannot be empty"
Got: "TextInputEditText{id=2131362003, res-name=login_password2, visibility=VISIBLE, width=996, height=141, has-focus=false, has-focusable=true, has-window-focus=true
Solution
It seems like you're matching a TextInputEditText in onView(Matcher) call instead of a TextInputLayout. The error text is set in TextInputLayout and not its child EditText. See this test.
Edit: You should also checkout this thread where it is suggested to use a custom matcher instead of hasErrorText().
Answered By - ashu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.