Java and Espresso - Can#39;t type in, needs to supports input methods or is assignable from class: class SearchView(Java和Espresso-can-t输入,需要支持输入法,或者可以从类:Class SearchView赋值)
问题描述
我正在尝试使用Espresso来测试具有此XML的应用程序:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tvLogin"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="myHint"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="56dp"
android:imeOptions="flagNoExtractUi|actionNext"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
这是我尝试运行的测试:
onView(withId(R.id.tvLogin)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
onView(withId(R.id.tvLogin)).perform(typeText("test"));
我收到此错误:
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: "TextInputLayout{id=2131362315, res-name=tvLogin, visibility=VISIBLE, width=831, height=144, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=androidx.constraintlayout.widget.ConstraintLayout$LayoutParams@8241b55, tag=null, root-is-layout-requested=false, has-input-connection=false, x=39.0, y=39.0, child-count=2}"
推荐答案
您的tvLogin
是TextInputLayout
,这也是LinearLayout
,所以当您在它上执行typeText()
时会出现错误。由于typeText()
仅适用于可编辑字段,并且TextInputEditText
是tvLogin
的后代,您可以重写测试以使用Espresso:
onView(allOf(supportsInputMethods(), isDescendantOfA(withId(R.id.tvLogin))))
.perform(typeText("test"))
或者,您也可以提供TextInputEditText
的ID:
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tvLoginEditText"
android:layout_width="match_parent"
android:layout_height="56dp"
android:imeOptions="flagNoExtractUi|actionNext"
android:inputType="text" />
,然后对可编辑字段执行typeText()
:
onView(withId(R.id.tvLoginEditText))
.perform(typeText("test"))
这篇关于Java和Espresso-can-t输入,需要支持输入法,或者可以从类:Class SearchView赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java和Espresso-can-t输入,需要支持输入法,或者可以从类:Class SearchView赋值


- 获取数字的最后一位 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 转换 ldap 日期 2022-01-01