正如标题所说,有时失败,有时成功。
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
的 Snackbar,这是正确的。
我很困惑,这是怎么回事?
这是我的测试代码:
activityRule.launchActivity(new Intent());
onView(withText("Network Error")).check(matches(isDisplayed()));
PS:当我运行整个测试服时,它大多失败了;但有时当我单独运行此测试时它也会失败。有时它会变成绿色,但没有任何图案,似乎是随机的。
最佳答案
晚了!但我希望它对其他人有帮助:
Testing Snackbar show with Espresso
private void checkSnackBarDisplayedByMessage(@StringRes int message) {
onView(withText(message))
.check(matches(withEffectiveVisibility(
ViewMatchers.Visibility.VISIBLE
)));
}
关于android - Snackbar 和 Espresso 有时会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35188183/