正如标题所说,它失败了一些,有些则失败了.
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,其可见性= VISIBLE,而text = Network Error是正确的.
我很困惑,发生了什么事?
这是我的测试代码:
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 ))); }