その要素値にアクセスするには、マッチャを作成する必要があります。
Matcher<View> hasValueEqualTo(final String content) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Has EditText/TextView the value: " + content);
}
@Override
public boolean matchesSafely(View view) {
if (!(view instanceof TextView) && !(view instanceof EditText)) {
return false;
}
if (view != null) {
String text;
if (view instanceof TextView) {
text = ((TextView) view).getText().toString();
} else {
text = ((EditText) view).getText().toString();
}
return (text.equalsIgnoreCase(content));
}
return false;
}
};
}
そして、このようにそれを呼び出す:
onView(withId(R.id.medical_summary_text_view))
.check(matches(hasValueEqualTo(value)));
またはテキストがあるだけかどうかを返すようにこの正規表現エンジンを編集することができ
それはテキストだ場合たとえば、あなたがチェックすることができますが、いくつかの値を持っています空かどうか:
Matcher<View> textViewHasValue() {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("The TextView/EditText has value");
}
@Override
public boolean matchesSafely(View view) {
if (!(view instanceof TextView) && !(view instanceof EditText)) {
return false;
}
if (view != null) {
String text;
if (view instanceof TextView) {
text = ((TextView) view).getText().toString();
} else {
text = ((EditText) view).getText().toString();
}
return (!TextUtils.isEmpty(text));
}
return false;
}
};
}
そして、このようにそれを呼び出す:
onView(withId(R.id.medical_summary_text_view))
.check(matches(textViewHasValue()));