我正在尝试使用 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>
Run Code Online (Sandbox Code Playgroud)
这是我尝试运行的测试:
onView(withId(R.id.tvLogin)).check(ViewAssertions.matches(ViewMatchers.isDisplayed()));
onView(withId(R.id.tvLogin)).perform(typeText("test"));
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
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, …
Run Code Online (Sandbox Code Playgroud)