我已经编写了代码来测试我的SearchView行为,但是失败了。标准方案只是我想在我的searcview中插入一些查询,然后提交
这是我的代码
onView(withId(R.id.search_match))
.perform(click())
onView(
withId(R.id.search_src_text)
).perform(replaceText("Arsenal"), closeSoftKeyboard(), pressKey(KeyEvent.KEYCODE_ENTER)) //failed here
我有这样的错误
androidx.test.espresso.PerformException: Error performing 'replace text(Arsenal)' on view 'with id: com.kuhaku.footballmatchschedule:id/search_src_text'.
我的xml代码
<androidx.cardview.widget.CardView
app:cardCornerRadius="12dp"
android:layout_marginHorizontal="8dp"
app:cardElevation="8dp"
android:id="@+id/card_search"
app:cardUseCompatPadding="true"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.SearchView
android:id="@+id/search_match"
app:queryHint="Search Match"
app:layout_constraintTop_toTopOf="parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.cardview.widget.CardView>
您可以通过使用资源-> getSystem-> getIdentifier到达搜索文本视图
Resources.getSystem().getIdentifier("search_src_text",
"id", "android")
[之后,您可以执行clearText(),然后键入所需的文本并单击键码,请输入
onView(withId(Resources.getSystem().getIdentifier("search_src_text",
"id", "android"))).perform(clearText(),typeText("enter the text"))
.perform(pressKey(KeyEvent.KEYCODE_ENTER))