[英]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=VISIBLE
而text=Network Error
是正确的。
我很困惑,发生了什么事?
这是我的测试代码:
activityRule.launchActivity(new Intent());
onView(withText("Network Error")).check(matches(isDisplayed()));
PS:当我运行整套测试服时,它大多失败了; 但有时当我单独运行此测试时它也会失败。 有时它会传递绿色,但没有任何模式,似乎是随机的。
晚的! 但我希望它对其他人有帮助:
private void checkSnackBarDisplayedByMessage(@StringRes int message) {
onView(withText(message))
.check(matches(withEffectiveVisibility(
ViewMatchers.Visibility.VISIBLE
)));
}
我遇到了类似的问题。 我能够通过以下方式解决它:
如上所述Disabeling动画这里 。
我从服务器获取数据后显示SnackBar,所以我还要等到获取数据。 我设法用这个 anwser中描述的IdlingResource来解决它。
然后我就能成功检查SnackBar。
我希望我的观点有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.