Forked from curioustechizen/EspressoTextInputLayoutUtils.java
Created
November 26, 2015 10:27
-
-
Save LOG-TAG/79e0731fe69c7ab333b6 to your computer and use it in GitHub Desktop.
Espresso utils for TextInputLayout
This file contains 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"))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment