【发布时间】:2016-08-10 12:42:54
【问题描述】:
我有一个包含 item.xml 项目的 RecyclerView。 在 item.xml 我有一个 TextView。
我正在创建一个仪器测试,并想知道如何从 recyclerView 的那个 textview 中获取文本,以便我可以用它做一些额外的工作。
使用https://spin.atomicobject.com/2016/04/15/espresso-testing-recyclerviews/,我设法检查了我期望的文本是否在我期望的位置,但我也需要获取值。
错误代码:
descendant: with string from resource id: <2131427419>' doesn't match the selected view when calling onView(withRecyclerView(R.id.recycler_view).atPosition(2)) .check(matches(hasDescendant(withText(R.id.my_textview))));
【问题讨论】:
-
您注意到了吗:
onView(withRecyclerView(R.id.scroll_view).atPosition(3)) .check(matches(hasDescendant(withText("Some content"))));?要获取TextView的值,请使用ViewMatchers.withText()方法 -
不过,withText(resourceId) 将返回一个 ViewInteraction,不明白我如何从中获取字符串。 (新测试)同样,我在调用
onView(withRecyclerView(R.id.recycler_view).atPosition(2)) .check(matches(hasDescendant(withText(R.id.my_textview))));时收到错误descendant: with string from resource id: <2131427419>' doesn't match the selected view -
请编辑您的帖子并将此代码添加为 EDIT
-
我也需要这个。 4 年后仍然没有答案。
标签: android testing android-espresso