【问题标题】:Testing Snackbar with Espresso用 Espresso 测试 Snackbar
【发布时间】:2016-02-04 15:43:31
【问题描述】:

我正在使用以下方法对其进行测试:

onView(allOf(withId(android.support.design.R.id.snackbar_text), withText("Network Error")))
        .check(matches(isDisplayed()));

但它在is displayed on the screen to the user 上失败很可能是因为y 坐标是0... x=18.0, y=0.0, ...

完整日志:

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}"

有什么想法吗?

【问题讨论】:

  • 请添加完整的 logcat。你只放了一部分
  • 这是最重要的部分,我想。问题是小吃店动画从 Y = 0 开始,因此,有时 espresso 会立即执行isDisplayed 检查,因为 Y = 0,它返回 false,即使小吃店存在并且存在于正确的根。我们放弃了这一点,转而进行期望测试。

标签: android-espresso android-snackbar


【解决方案1】:

您可以使用 withEffectiveVisibility 代替 isDisplayed,因此它是否实际显示在当前屏幕中并不重要:

private void checkSnackBarDisplayedByMessage(@StringRes int message) {
    onView(allOf(withId(android.support.design.R.id.snackbar_text), withText(message)))
        .check(matches(withEffectiveVisibility(
            ViewMatchers.Visibility.VISIBLE
    )));
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多