2016-05-12 34 views
2

我有一個應用程序,具有的ListView,我想找到的LinearLayout '負載適配器數據',ID = order_untake_jijia_listview_jia咖啡昂達錯誤執行上視圖

enter image description here

代碼是:

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}" 
+0

我想找到「order_untake_jijia_listview_ll」小孩「order_untake_jijia_listview_jia」,但找到它的父親.... –

+0

請重新格式化。 –

+0

我認爲在更新版本的Espresso中,這不再是一個問題。 – 476rick

回答

0

您正在使用onData不正確。 onData需要對象匹配器 - 它旨在匹配用於填充列表的自定義模型對象。所以如果你有一個簡單的字符串列表,你會說onData(instanceOf(String.class)).atPosition(0)onData(is("This exact String at position 0"))

inAdapterView用於匹配包含您的數據的特定適配器視圖實例。當屏幕上有多個列表需要區分時,您需要使用此列表。例如,如果您有一個名爲R.id.list1ListView和第二個R.id.list2均包含String s,您會說onData(is("The String")).inAdapterView(withId(R.id.list1))與第一個列表中的對象匹配。

如果您只需點擊適配器中的單個項目,您通常也不需要在這些情況下指定子視圖。您通常使用onChildView對子查看項目執行斷言,或者如果您碰巧在該子視圖上有單獨的專用點擊偵聽器。

因此,它好像你已經過於複雜的情況,你應該可以更新您的代碼是這樣的:

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

如果不解決您的問題,請提供一些佈局你的列表項目的代碼以及具有列表視圖的主屏幕布局,以及一個顯示示例的屏幕截圖,並闡明你想要匹配/行動/斷言的內容,我可以嘗試引導你到你需要完成你所需要的正確的一套方法。

希望有幫助!