2016-06-10 122 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()使用更详细。