Tôi đang cố gắng kiểm tra văn bản của ActionPage bằng Espresso. Tuy nhiên, khi tôi chạy Trình xem tự động Ui, tôi có thể thấy rằng ActionPage đang được hiển thị dưới dạng dạng xem thay vì một ActionView và nó không có TextView.Thử nghiệm Ui Android Espresso xác minh văn bản nhãn của ActionPage
Tôi đã thử kiểm tra các văn bản ActionLabel như thế này nhưng điều đó không làm việc:
onView(withClassName(equalToIgnoringCase("android.support.wearable.view.ActionLabel"))).check(matches(withText("MyText")));
Tôi có một id cho ActionPage của tôi để tôi có thể tìm thấy nó với onView(withId(R.id.actionPage))
nhưng tôi không biết làm thế nào để truy cập vào con của nó để lấy văn bản ActionLabel. Tôi đã cố gắng viết một khớp tùy chỉnh nhưng điều này cũng không làm việc:
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);
}
};
}
Có thể ai đó hãy giúp tôi ra, ActionLabel dường như không có một id của chính nó và nó không phải là một TextView ... làm thế nào tôi có thể kiểm tra văn bản bên trong của nó?
+------>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}
Có thể thêm mô tả hoặc id nội dung theo chương trình vào ít nhất một trong các bố cục này không? Sẽ dễ dàng hơn nếu bắt được – piotrek1543