2016-06-10 147 views
1

我有一個ExpandableListView,我想click()它的孩子之一。濃咖啡 - 爲什麼濃咖啡找到這個匹配模糊?

我試過LOADS OF不同的方式,但我似乎無法理解Espresso是如何工作的。

例如,爲什麼此代碼不起作用?

onData(withId(R.id.execexpList)).onChildView(is(withId(200))).perform(click()) 

出於某種神聖的原因,則返回「曖昧比賽」我的ExpandableLIstView和我的其他的ListView,但他們有不同的ID。

任何人都可以幫我嗎?

+0

不應該'withId'採取'R.id'? –

+0

@JaredBurrows我已經將我的'ExpandableListView'中的每一行設置爲一個特定的ID。這就是爲什麼我硬編碼它 – RafaelC

+0

你在視圖上使用了'setId'嗎?首先嚐試'withId(is(int))'。請參閱https://developer.android.com/reference/android/support/test/espresso/matcher/ViewMatchers.html#withId(int)。如果這不起作用,請嘗試'setTag'。然後使用https://developer.android.com/reference/android/support/test/espresso/matcher/ViewMatchers.html#withTagKey(int)。 –

回答

1

onData()用於匹配ListView適配器內的項目,而不是實際視圖。

onChildView()用於匹配在onData()中匹配的ListView項目的後代。

如果在層次結構中有多個AdapterView,則必須改用inAdapterView(Matcher<View>viewMatcher)

官方API guide說明onData()使用更詳細。