Android的测试。 ES preSSO。在一个TextView更改文本 [英] Android testing. Espresso. Change text in a TextView
本文介绍了Android的测试。 ES preSSO。在一个TextView更改文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是很容易更新以E preSSO一个EditText,但我不能找到一种方法来更改文本(就像一个TextView.setText(SomeText则会);方法)。在测试过程中
It is easy to update an EditText with Espresso, but I can not find a way to change a text (like with a TextView.setText("someText"); method) during the testing process.
ViewAction.replaceText(stringToBeSet);
不工作,因为这一切应该是一个EditText;
Is not working, cos it should be an EditText;
推荐答案
您可以考虑实现自己的ViewAction这一。
You can look into implementing your own ViewAction.
下面是ES preSSO库replaceText ViewAction这一,是为了上工作的修改版本的的TextView
。
Here is the modified version of the replaceText viewaction from espresso library that is meant to work on the 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";
}
};
}
这篇关于Android的测试。 ES preSSO。在一个TextView更改文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文