Android espresso 在浓缩咖啡中从下拉列表中选择项目

Android espresso 在浓缩咖啡中从下拉列表中选择项目,android-espresso,android-adapterview,Android Espresso,Android Adapterview,我正在尝试编写一个浓缩咖啡测试,它将导航到搜索,键入两个字母以获得增量搜索,然后点击列表中的第二项 结果显示在适配器中 当然,第一部分我做得很好,但是当我需要单击列表中的项目时,出现了一个问题 我已经试过了 onData(anything()).inAdapterView(withId(R.id.searchContainer)).atPosition(1).perform(click()) 及 (其中某些搜索是结果的完整文本) 及 (其中text1是结果字段的id) 它应该点击结果并打开新的

我正在尝试编写一个浓缩咖啡测试,它将导航到搜索,键入两个字母以获得增量搜索,然后点击列表中的第二项

结果显示在适配器中

当然,第一部分我做得很好,但是当我需要单击列表中的项目时,出现了一个问题

我已经试过了

onData(anything()).inAdapterView(withId(R.id.searchContainer)).atPosition(1).perform(click())

(其中某些搜索是结果的完整文本)

(其中text1是结果字段的id)

它应该点击结果并打开新的屏幕/活动,我将在那里做我的断言

目前,我遇到以下错误:

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 assignable from class: class android.widget.AdapterView and is displayed on the screen to the user)
Target view: "ce{id=-1, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@4d102dd, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}"

任何建议,都会让我发疯。。。谢谢:)

我需要查看视图,以确保%99%的用户不需要使用onData,只需使用onView即可(使用文本(containsString(yourSearchFilter))。执行(单击()


可能还有一个与withText(containssString(text))相对应的withSubstring(text))

我需要查看视图以确保,但%99%的用户不需要使用onData,只需使用onView即可(withText(containssString(yourSearchFilter))。执行(单击()


可能还有一个与withText(containssString(text))相对应的withSubstring(text)

我也尝试过类似的东西:``onData(allOf(
(instanceOf(String::class.java)),
(“火腿三明治”)。执行(click())``但它没有工作,这很奇怪,因为这是一个精确的硬编码结果…我还尝试了类似的东西:``onData(allOf(
(instanceOf(String::class.java)),
(“火腿三明治”))。执行(click())``但它不起作用,这很奇怪,因为这是一个精确的硬编码结果…不幸的是,no.androidx.test.espresso.nomatchingvieweexception:在层次结构中找不到匹配的视图:与文本:包含“搜索词”的字符串如果目标视图不是视图层次结构的一部分,则可能需要使用espresso.onData从以下AdapterViews之一加载它:com.google.maps…不幸的是,no.androidx.test.espresso.nomatchingvieweexception:在层次结构中找不到匹配的视图:与文本:包含“搜索词”的字符串如果目标视图不属于视图层次结构,则可能需要使用espresso.onData从以下AdapterViews之一加载它:com.google.maps。。。。
onData(withId(android.R.id.text1)).atPosition(1).perform(click())
    @Test
    fun searchForSandwich() {

        onView(withId(R.id.textSearch)).perform(typeText("ha"))

        onData(withChild(withText("Ham Sandwich"))).atPosition(1).perform(click())
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 assignable from class: class android.widget.AdapterView and is displayed on the screen to the user)
Target view: "ce{id=-1, visibility=GONE, width=0, height=0, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=true, is-selected=false, layout-params=android.widget.RelativeLayout$LayoutParams@4d102dd, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=0}"