19

我对 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/text_product_verdictID……而这个 ID 来自另一个活动……测试活动是正确的

@Rule public ActivityTestRule<HomeActivity> mActivityTestRule = new ActivityTestRule<>(HomeActivity.class);

我查看了 FTL 测试失败的视频,并在 FTL 的模拟器img上看到了很多通知

我认为问题是来自 Google Hangouts 的粘性通知,并尝试使用--no-auto-google-login标志运行我的测试。但有相同的结果。通过onView(withText("Air conditioners")).check(matches(isDisplayed()));FTL 测试。

有人可以帮忙解决问题吗?

4

3 回答 3

1

它也发生在我身上。Firebase 测试实验室似乎无法识别某些设备中的idwithId(R.id.text_supercategory_name)。我们可以使用res-name来代替。

查看日志中的视图层次结构并在其中获取 res-nameonView(withResourceName("res-name")).perform(click());

// 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}
于 2019-05-29T14:11:27.107 回答
1

我在使用浓缩咖啡时也发现了这个问题。然后我用咖啡师做浓缩咖啡包装。它帮助我选择使用 R.id.name 或 R.string.name 或“名称”作为选择器。在这里单击他们 GitHub 中的示例:

clickOn(R.id.button);
clickOn(R.string.button_text);
clickOn("Next");
于 2020-02-06T11:07:54.650 回答
0

视图的 ID(整数值)在每个构建中动态更改。当应用程序和测试 apk 的相同版本上传到 firebase 时,它​​可以工作。但是,当上传不同的版本时,它会失败。

于 2021-01-25T15:04:51.027 回答