Espresso kullanarak bir ActionPage metnini test etmeye çalışıyorum. Ancak, Ui Automation Viewer'ı çalıştırdığımda, ActionPage'in bir ActionView yerine View olarak gösterildiğini ve TextView içermediğini görebiliyorum.Android Espresso Ui Testin etiket metnini doğrulayın ActionPage
böyle ActionLabel metin için denetimi denedim ama bu işe yaramazsa: Ben bu yüzden onView(withId(R.id.actionPage))
ile bulabilirsiniz benim ActionPage için bir kimliği var ama onun çocukları erişmek için nasıl bilmiyorum
onView(withClassName(equalToIgnoringCase("android.support.wearable.view.ActionLabel"))).check(matches(withText("MyText")));
ActionLabel metnine ulaşmak için. Özel bir eşleyici yazmaya çalıştım ama bu da işe yaramazsa:
onView(withId(R.id.actionPage)).check(matches(withChildText("MyText")));
static Matcher<View> withChildText(final String string) {
return new BoundedMatcher<View, View>(View.class) {
@Override
public boolean matchesSafely(View view) {
ViewGroup viewGroup = ((ViewGroup) view);
//return (((TextView) actionLabel).getText()).equals(string);
for(int i = 0; i < view.getChildCount(); i++){
View child = view.getChildAt(i);
if (child instanceof TextView) {
return ((TextView) child).getText().toString().equals(string);
}
}
return false;
}
@Override
public void describeTo(Description description) {
description.appendText("with child text: " + string);
}
};
}
birisi, ActionLabel nasıl kontrol edebilirim ... kendisi ve onun değil TextView tarafından bir kimliği olması görünmüyor bana yardım eder misiniz içindeki metin? Maalesef ActionLabel
getText()
aracılığıyla metnini göstermiyor
onView(
allOf(
withParent(withId(R.id.actionPage)),
isAssignableFrom(ActionLabel.class)))
.check(matches(withActionLabel(is("MyText"))));
, bu yüzden yerine standart withText()
Eşleştirici nedeniyle, özel bir yazmak zorunda:
+------>FrameLayout{id=-1, visibility=VISIBLE, width=320, height=320, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+------->ActionPage{id=2131689620, res-name=actionPage, visibility=VISIBLE, width=320, height=320, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
+-------->ActionLabel{id=-1, visibility=VISIBLE, width=285, height=111, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=17.0, y=209.0}
|
+-------->CircularButton{id=-1, visibility=VISIBLE, width=144, height=144, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=88.0, y=65.0}
Bu düzenlerden en az birine programlı içerik açıklaması veya kimliği eklemek mümkün mü? – piotrek1543