Created
February 1, 2017 15:37
-
-
Save ubaierbhat/22e0c6c2d3073cd140bb22159473ced6 to your computer and use it in GitHub Desktop.
Alternative to performing typeText in an Android Expresso test.
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
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