Android Espresso-如何检查EditText提示? [英] Android Espresso - How to check EditText hint?

查看:65
本文介绍了Android Espresso-如何检查EditText提示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始玩Espresso,开始进行基本测试.现在尝试弄清楚如何检查我的编辑文本是否具有特定的提示文本?谢谢.

I'm starting to play with Espresso, got my basic tests running. Now trying to figure out how to check that my edit text has a specific hint text? Thanks.

onView(withId(R.id.locationInput)).check(matches...?)

推荐答案

看起来像我想通了.基本上,您需要创建自己的匹配器:

Looks like I figured it out. Basically, you need to create your own matcher:

public static Matcher<View> withHint(final String expectedHint) {
    return new TypeSafeMatcher<View>() {

        @Override
        public boolean matchesSafely(View view) {
            if (!(view instanceof EditText)) {
                return false;
            }

            String hint = ((EditText) view).getHint().toString();

            return expectedHint.equals(hint);
        }

        @Override
        public void describeTo(Description description) {
        }
    };
}

然后您可以使用它:

onView(withId(R.id.locationInput)).check(matches(withHint("Location (Optional)")));

这篇关于Android Espresso-如何检查EditText提示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆