And*_*rey 5 testing android textview android-espresso
使用Espresso更新EditText很容易,但是在测试过程中我找不到改变文本的方法(比如使用TextView.setText("someText");方法).
ViewAction.replaceText(stringToBeSet);
Run Code Online (Sandbox Code Playgroud)
不工作,因为它应该是一个EditText;
Be_*_*ive 18
您可以考虑实现自己的ViewAction.
以下是来自espresso库的replaceText viewaction的修改版本,该版本适用于TextView.
public static ViewAction setTextInTextView(final String value){
return new ViewAction() {
@SuppressWarnings("unchecked")
@Override
public Matcher<View> getConstraints() {
return allOf(isDisplayed(), isAssignableFrom(TextView.class));
}
@Override
public void perform(UiController uiController, View view) {
((TextView) view).setText(value);
}
@Override
public String getDescription() {
return "replace text";
}
};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3985 次 |
| 最近记录: |