简体   繁体   English

Android espresso 测试在本地通过,但在 Firebase 测试实验室失败

[英]Android espresso test pass locally but fails on Firebase Test Lab

I have issue with android espresso test.我有 android espresso 测试的问题。 Test pass locally but fail on FTL.测试在本地通过但在 FTL 上失败。 It's simple test测试很简单

onView(allOf(withId(R.id.text_supercategory_name), withText("Air conditioners"))). check(matches(withText("Air conditioners")));

this test pass locally.此测试在本地通过。 On FTL I have error:在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")

I'm not understand whay I see ID which not used in my test id/text_product_verdict … and this ID from another activity … Activity for test is correct我不明白为什么我看到的 ID 没有在我的测试id/text_product_verdict ……而这个 ID 来自另一个活动……测试活动是正确的

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

I checked the video of the failed test on FTL and see a lot of notifications on emulator img from FTL我在 FTL 上查看了失败测试的视频,并在来自 FTL 的模拟器img上看到了很多通知

I decide that the problem was a sticky notification from Google Hangouts and try run my test with --no-auto-google-login flag.我认为问题是来自 Google Hangouts 的粘性通知,并尝试使用--no-auto-google-login标志运行我的测试。 But have the same results.但有相同的结果。 With onView(withText("Air conditioners")).check(matches(isDisplayed()));随着onView(withText("Air conditioners")).check(matches(isDisplayed())); test pass on FTL.测试通过 FTL。

Is anyone can help with with issue?有人可以帮忙解决问题吗?

It happened to me as well.它也发生在我身上。 It seems Firebase Test Lab does not recognize the id at withId(R.id.text_supercategory_name) in some devices. Firebase 测试实验室似乎无法识别某些设备中withId(R.id.text_supercategory_name)处的ID We can use res-name instead.我们可以使用res-name代替。

Check out the view hierarchy in the log and grab the res-name in there with onView(withResourceName("res-name")).perform(click());查看日志中的视图层次结构并使用onView(withResourceName("res-name")).perform(click());获取其中的 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}

I found this issue also when using espresso.我在使用浓缩咖啡时也发现了这个问题。 Then I using Barista for espresso wrapper.然后我使用咖啡师制作浓缩咖啡包装纸。 It's helping me to choose using R.id.name or R.string.name or "name" as the selector.它帮助我选择使用 R.id.name 或 R.string.name 或“name”作为选择器。 Here click example from their GitHub :这里从他们的 GitHub 单击示例:

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

The ID(integer value) of the view is dynamically changed in each build.视图的 ID(整数值)在每次构建中都会动态更改。 It works when when the same build of the app and test apk are upload to firebase.当应用程序的相同版本和测试 apk 上传到 firebase 时,它​​会起作用。 However when different builds are uploaded, it fails.但是,当上传不同的构建时,它会失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM