我在我的安卓应用中有一个TextInputEditText视图,并通过Anko和Kotlin进行编程设置,代码如下:
在 Espresso 测试中,我调用了以下这行代码:
textInputEditText {
id = R.id.text_input_id
inputType = EditorInfo.TYPE_TEXT_VARIATION_NORMAL
hint = resources.getText(R.string.text_hint)
}
在 Espresso 测试中,我调用了以下这行代码:
onView(withId(R.id.text_input_id)).perform(typeText(textToType))
这会导致以下错误:
Caused by: java.lang.RuntimeException: Action will not be performed because the target view does not match one or more of the following constraints:
((is displayed on the screen to the user) and (supports input methods or is assignable from class: class android.widget.SearchView))
Target view: "TextInputEditText{id=2131623954, res-name=text_input_id, visibility=VISIBLE, width=862, height=118, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, text=, input-type=0, ime-target=false, has-links=false}"
我发现如果我把它从这个位置切换到:
/**
* Default variation of {@link #TYPE_CLASS_TEXT}: plain old normal text.
*/
public static final int TYPE_TEXT_VARIATION_NORMAL = 0x00000000;
转换为:
/**
* Variation of {@link #TYPE_CLASS_TEXT}: entering a password, which should
* be visible to the user.
*/
public static final int TYPE_TEXT_VARIATION_VISIBLE_PASSWORD = 0x00000090;
它突然神奇地工作了!但这并没有太多意义。正常的文本听起来像是正确的,直到Espresso在我的脸上爆炸。这是Espresso的错误,还是我没有理解?