私はEspressoを使用してActionPageのテキストをテストしようとしています。しかし、Ui Automation Viewerを実行すると、ActionPageはActionViewではなくViewとして表示され、TextViewは表示されません。Android Espresso Ui TestはActionPageのラベルテキストを確認します
私はこのようなActionLabelテキストをチェックしようとしたが、それは動作しません:
onView(withClassName(equalToIgnoringCase("android.support.wearable.view.ActionLabel"))).check(matches(withText("MyText")));
私はonView(withId(R.id.actionPage))
でそれを見つけることができますので、私は私のActionPageのIDを持っているが、私はその子にアクセスする方法を知りませんActionLabelテキストを取得します。私は、カスタム照合を書いてみましたが、これも動作しません:
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);
}
};
}
誰かが私を助けてもらえ、ActionLabelは自身とそのないのTextViewでIDを持っていないようです...どのように私は確認することができますそれの中のテキスト?
+------>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}
このレイアウトの少なくとも1つにコンテンツ記述またはIDをプログラムで追加することはできますか?キャッチする方がはるかに簡単です – piotrek1543