正如標題所說,它有時會失敗,有些則失敗。Snackbar和Espresso有時會失敗
android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'is displayed on the screen to the user' doesn't match the selected view.
Expected: is displayed on the screen to the user
Got: "AppCompatTextView{id=2131492981, res-name=snackbar_text, visibility=VISIBLE, width=444, height=71, 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=18.0, y=0.0, text=Network Error, input-type=0, ime-target=false, has-links=false}"
堆棧跟蹤的第一行表明espresso無法在屏幕上看到Snackbar。但第二行表明它實際上看到一個小吃店visibility=VISIBLE
和text=Network Error
這是正確的。
我很困惑,這是怎麼回事?
這是我的測試代碼:
activityRule.launchActivity(new Intent());
onView(withText("Network Error")).check(matches(isDisplayed()));
PS:當我運行整個測試套裝它主要是失敗;但有時它也會失敗,因爲我只是單獨運行這個測試。有些時候它會變綠,但沒有任何圖案,看起來是隨機的。
謝謝!我很高興有這樣的解決方案,不需要放棄UI測試。 – AdamMc331
其實我也試過這個,我也遇到同樣的問題。 :( – AdamMc331