Android Espresso测试本地通过,但在Firebase Test Lab上失败

21
我有一个关于Android Espresso测试的问题。 本地测试通过但在FTL上失败了。这是一个简单的测试。 onView(allOf(withId(R.id.text_supercategory_name), withText("Air conditioners"))). check(matches(withText("Air conditioners"))); 这个测试本地测试通过,但在FTL上我看到以下错误: android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (with id: blablabla:id/text_product_verdict and with text: is "Air conditioners") 我不明白为什么会出现没有在我的测试中使用的ID id/text_product_verdict …而且这个ID来自另一个活动… 测试用的活动是正确的。 @Rule public ActivityTestRule<HomeActivity> mActivityTestRule = new ActivityTestRule<>(HomeActivity.class); 我检查了在FTL上失败的测试视频,并看到模拟器上有很多通知消息。 来自FTL的图片 我决定问题可能是来自Google Hangouts的粘性通知,尝试使用--no-auto-google-login标志运行测试。但结果相同。使用onView(withText("Air conditioners")).check(matches(isDisplayed())); 测试可以在FTL上通过。
有人能帮忙解决这个问题吗?

2
有关此事有任何更新吗?我也遇到了同样的问题。 - Liuting
3个回答

1
我也遇到过这种情况。似乎Firebase测试实验室在某些设备上无法识别withId(R.id.text_supercategory_name)中的id。我们可以使用res-name代替。
检查日志中的视图层次结构,并使用onView(withResourceName("res-name")).perform(click());抓取其中的res-name
// change res-name to buttonPanel, button3, button2, or button1
+---->ScrollView{id=16908757, res-name=buttonPanel, visibility=VISIBLE, width=1008, height=217, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=1507.0, child-count=1}
|
+----->ButtonBarLayout{id=-1, visibility=VISIBLE, width=1008, height=217, has-focus=false, has-focusable=true, 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=4}
|
+------>AppCompatButton{id=16908315, res-name=button3, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=true, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}
|
+------>Space{id=16909293, res-name=spacer, visibility=INVISIBLE, width=429, height=0, 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=42.0, y=203.0}
|
+------>AppCompatButton{id=16908314, res-name=button2, visibility=VISIBLE, width=271, height=189, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=471.0, y=14.0, text=Cancel, input-type=0, ime-target=false, has-links=false}
|
+------>AppCompatButton{id=16908313, res-name=button1, visibility=VISIBLE, width=224, height=189, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=742.0, y=14.0, text=OK, input-type=0, ime-target=false, has-links=false}

1
我发现在使用Espresso时也遇到了这个问题。然后我使用Barista作为Espresso包装器。它帮助我选择使用R.id.name、R.string.name或"name"作为选择器。 这里是他们在GitHub上的示例:
clickOn(R.id.button);
clickOn(R.string.button_text);
clickOn("Next");

0

视图的ID(整数值)在每个构建中动态更改。当应用程序和测试apk的同一版本上传到Firebase时,它可以正常运行。但是,当不同版本被上传时,它会失败。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接