其他分享
首页 > 其他分享> > android – Espresso检查视图是否isExotExist isDisplayed

android – Espresso检查视图是否isExotExist isDisplayed

作者:互联网

以下语句不起作用,因为doesNotExist()返回ViewAssertion而不是匹配器.没有try-catch的任何方式使它工作?

.check(either(matches(doesNotExist())).or(matches(not(isDisplayed()))));

解决方法:

我有同样的问题,我的一个观点最初没有某个视图,但可以添加它并稍后隐藏它.用户界面依赖于哪些状态的背景活动被破坏了.

我最后只是编写了一个关于doesNotExist实现的变体:

public class ViewAssertions {
    public static ViewAssertion doesNotExistOrGone() {
        return new ViewAssertion() {
            @Override
            public void check(View view, NoMatchingViewException noView) {
                if (view != null && view.getVisibility() != View.GONE) {
                    assertThat("View is present in the hierarchy and not GONE: "
                               + HumanReadables.describe(view), true, is(false));
                }
            }
        };
    }
}

标签:android,hamcrest,android-espresso
来源: https://codeday.me/bug/20190627/1308820.html