簡體   English   中英

Snackbar和Espresso有時會失敗

[英]Snackbar and Espresso failing sometimes

正如標題所說,它失敗了一些,有些則失敗了。

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。 但第二行說明它實際上是看到一個Snackbar,其visibility=VISIBLEtext=Network Error是正確的。

我很困惑,發生了什么事?

這是我的測試代碼:

activityRule.launchActivity(new Intent());
onView(withText("Network Error")).check(matches(isDisplayed()));

PS:當我運行整套測試服時,它大多失敗了; 但有時當我單獨運行此測試時它也會失敗。 有時它會傳遞綠色,但沒有任何模式,似乎是隨機的。

晚的! 但我希望它對其他人有幫助:

使用Espresso測試Snackbar節目

private void checkSnackBarDisplayedByMessage(@StringRes int message) {
    onView(withText(message))
        .check(matches(withEffectiveVisibility(
            ViewMatchers.Visibility.VISIBLE
    )));
}

我遇到了類似的問題。 我能夠通過以下方式解決它:

  1. 如上所述Disabeling動畫這里

  2. 我從服務器獲取數據后顯示SnackBar,所以我還要等到獲取數據。 我設法用這個 anwser中描述的IdlingResource來解決它。

然后我就能成功檢查SnackBar。

我希望我的觀點有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM