Last active
April 10, 2019 14:36
-
-
Save curioustechizen/096ad82763669acc0b55 to your computer and use it in GitHub Desktop.
DEPRECATED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EspressoTextInputLayoutUtils{ | |
/* | |
* Use this method to find the EditText within the TextInputLayout. Useful for typing into the TextInputLayout | |
*/ | |
public static ViewInteraction onEditTextWithinTilWithId(@IdRes int textInputLayoutId) { | |
//Note, if you have specified an ID for the EditText that you place inside | |
//the TextInputLayout, use that instead - i.e, onView(withId(R.id.my_edit_text)); | |
return onView(allOf(isDescendantOfA(withId(textInputLayoutId)), isAssignableFrom(EditText.class))); | |
} | |
/* | |
* Use this method to find the error view within the TextInputLayout. Useful for asseting that certain errors are displayed to the user | |
*/ | |
public static ViewInteraction onErrorViewWithinTilWithId(@IdRes int textInputLayoutId) { | |
return onView(allOf(isDescendantOfA(withId(textInputLayoutId)), not(isAssignableFrom(EditText.class)), isAssignableFrom(TextView.class))); | |
} | |
//Example usage | |
@Test | |
public void testUsernameTooShortShowsError(){ | |
onEditTextWithinTilWithId(R.id.tilUsername).perform(typeText("user123"), closeSoftKeyboard()); | |
onView(withId(R.id.sign_up)).perform(click());//Assume there is a button that you click | |
onErrorViewWithinTilWithId(R.id.tilUsername).check(matches(withText("Username too short"))); | |
} | |
} |
onErrorViewWithinTilWithId doesn't workr for me
@stMayhem what problem do you see? Is the error view not found at all?
I have not updated this gist in 2 years and it is possible that the implementation of TextInputLayout has changed recently thus causing this code to break (you might have noted that it depends on implementation details of TIL).
here also does not work, it asks to create the class matches
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you very much :)