【问题标题】:Android espresso test pass locally but fails on Firebase Test LabAndroid espresso 测试在本地通过,但在 Firebase 测试实验室失败
【发布时间】:2017-10-05 13:13:18
【问题描述】:

我对 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 测试失败的视频,并在模拟器上看到了很多通知 img from FTL

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

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

【问题讨论】:

  • 这方面有什么更新吗?我也有同样的问题

标签: android firebase automation android-espresso firebase-test-lab


【解决方案1】:

这也发生在我身上。在某些设备中,Firebase 测试实验室似乎无法识别 withId(R.id.text_supercategory_name) 处的 id。我们可以改用 res-name

查看日志中的视图层次结构并使用onView(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}

【讨论】:

    【解决方案2】:

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

    clickOn(R.id.button);
    clickOn(R.string.button_text);
    clickOn("Next");
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-16
        • 1970-01-01
        • 2018-12-18
        相关资源
        最近更新 更多