Skip to content

Instantly share code, notes, and snippets.

@ubaierbhat
Created February 1, 2017 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ubaierbhat/22e0c6c2d3073cd140bb22159473ced6 to your computer and use it in GitHub Desktop.
Save ubaierbhat/22e0c6c2d3073cd140bb22159473ced6 to your computer and use it in GitHub Desktop.
Alternative to performing typeText in an Android Expresso test.
public class SetTextAction implements ViewAction {
private String stringToBeTyped;
public SetTextAction(String stringToBeTyped) {
this.stringToBeTyped = stringToBeTyped;
}
@Override
public Matcher<View> getConstraints() {
return Matchers.allOf(isDisplayed(), isAssignableFrom(EditText.class));
}
@Override
public String getDescription() {
return String.format("SetTextAction type text(%s)", stringToBeTyped);
}
@Override
public void perform(UiController uiController, View view) {
if (!TextUtils.isEmpty(stringToBeTyped)) {
((EditText) view).setText(stringToBeTyped);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment