Android Espresso无法输入TYPE_TEXT_VARIATION_NORMAL?

我在我的Android应用程序中有一个TextInputEditText视图,我正在通过编程(通过Anko和Kotlin)来设置它:

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; 

它突然神奇的作品! 但是这没有什么意义。 正常的文字听起来像是正确的使用,直到浓咖啡爆炸在我的脸上。 这是一个咖啡的错误,或者我不理解的东西?

我的猜测是,这是发生在typeText调用内部。 请参阅TypeTextAction.getConstraints()中的约束列表。 逻辑基本上是:

 isDisplayed() && hasFocus() && ( supportsInputMethods() || isAssignableFrom(SearchView.class) ) 

我的第一个猜测是,它没有通过supportsInputMethods()约束。 您可以在ViewMatchers.supportsInputMethods() -> matchesSafely()放置一个断点并自己查看。