Espresso onData在视图上执行“加载适配器数据”时出错 [英] Espresso onData Error performing 'load adapter data' on view

查看:583
本文介绍了Espresso onData在视图上执行“加载适配器数据”时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,有ListView,我想找到LinearLayout,id = order_untake_jijia_listview_jia

I have an app, have ListView, I want to find LinearLayout, id=order_untake_jijia_listview_jia

代码是:

onData(withClassName(endsWith("ListView")))
            .inAdapterView(allOf(withId(R.id.order_untake_jijia_listview_ll), hasSibling(withText("9.0"))))
            .atPosition(0).onChildView(withId(R.id.order_untake_jijia_listview_jia));
            dataInteraction.perform(ViewActions.click());

但我有错误:

Error performing 'load adapter data' on view '(with id: com.edaixi:id/order_untake_jijia_listview_ll and has sibling: with text: is "9.0")'.
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: "LinearLayout{id=2131493753, res-name=order_untake_jijia_listview_ll, visibility=VISIBLE, width=170, height=50, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=572.0, y=25.0, child-count=3}"


推荐答案

您正在错误地使用 onData
onData 接受对象匹配器 - 它旨在匹配用于填充列表的自定义模型对象。所以,如果你有一个简单的字符串列表,你会说 onData(instanceOf(String.class))。atPosition(0) onData(是(这个位置0的确切字符串))

You are using onData incorrectly. onData takes an object matcher - it's intended to match the custom model object that is used to populate the list. So if you had a list of simple Strings, you would say onData(instanceOf(String.class)).atPosition(0) or onData(is("This exact String at position 0")).

inAdapterView 被使用匹配包含数据的特定适配器视图实例。当您需要在屏幕上显示多个列表时,您需要这样做。例如,如果您有一个名为 R.id.list1 ListView 和第二个 R .id.list2 都包含 String s,你会说 onData(是(The String))。inAdapterView (withId(R.id.list1))匹配第一个列表中的对象。

inAdapterView is used to match the specific adapter view instance that contains your data. You need this when you have multiple lists on the screen you need to distinguish against. For example, if you had one ListView named R.id.list1 and a second R.id.list2 both containing Strings, you would say onData(is("The String")).inAdapterView(withId(R.id.list1)) to match the object in the first list.

您通常也不需要指定如果您只需要单击适配器中的单个项目,则在这些情况下显示子视图。您通常使用 onChildView 对子视图项执行断言,或者如果您恰好在该子视图上有单独的专用单击侦听器。

You also generally do not need to specify a child view in these cases if you just need to click a single item in the adapter. You generally use onChildView to do an assertion on a child view item, or if you happen to have a separate dedicated click listener on that sub-view.

因此,似乎你的情况过于复杂,你应该能够将你的代码更新为:

Thus, it seems as though you've overcomplicated the situation and you should be able to update your code to something like this:

onData(instanceOf(MyCustomClassOfObjectsInAdapter.java))
    .atPosition(0)
    .perform(click());

如果这不能解决您的问题,请提供一些列表项目的布局代码以及包含listview的主屏幕布局,以及带有显示示例的屏幕截图,并阐明你想要匹配/行动/断言的内容,我可以尝试引导你找到你需要的正确方法集完成你需要的东西。

If that doesn't solve your problem, please provide some layout code of what your list items look like as well as the main screen layout that has the listview, and a screenshot with an example of the display and clarify what you're trying to match / act / assert against and I can try to guide you to the correct set of methods you need to accomplish what you need.

希望有所帮助!

这篇关于Espresso onData在视图上执行“加载适配器数据”时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆