【发布时间】:2016-01-06 10:16:43
【问题描述】:
我想查看Save €XX在列表中的显示。 Save €XX 是一个 TextView,可以是 VISIBLE 或 INVISIBLE。我使用 JUnit 4 和 Espresso 2.2.1。
我试着这样检查:
onView(withText(startsWith("Save"))).check(matches(isDisplayed()));
但总是报错:
android.support.test.espresso.AmbiguousViewMatcherException: 'with text: a string starting with "Save"' matches multiple views in the hierarchy.
有没有办法用 Espresso 判断 TextView 是否存在于 ListView 中?
更新
我也试过用onData:
onData(hasToString(startsWith("Save")))
.inAdapterView(withId(R.id.suggestion_list_view)).atPosition(0)
.check(matches(isDisplayed()));
但onData 似乎适用于数据层,但不适用于视图层。因此,我收到错误:
java.lang.RuntimeException: No data found matching: with toString() a string starting with "Save" contained values: <[Data: ...]>
【问题讨论】:
标签: android junit junit4 android-espresso