【发布时间】:2020-04-01 14:40:24
【问题描述】:
我编写了代码来测试我的 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>
【问题讨论】:
-
应用加载时
R.id.search_src_text的文字内容是什么? -
什么都没有,只是空白
-
它试图用一些东西替换“Arsenal”这个词,但它找不到要替换的文本。也许盒子里可以有那个词来代替,或者可以修改测试
-
我尝试使用 'typeText("Arsenal)' 但仍然显示相同的错误
标签: android testing kotlin android-espresso searchview