Adr*_*man 5 testing android android-espresso
我有一个 RecyclerView,其中包含 item.xml 中的项目。在 item.xml 我有一个 TextView。
我正在创建一个工具测试,想知道如何从 recyclerView 中获取该文本视图中的文本,以便我可以对它做一些额外的工作。
使用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))));
Run Code Online (Sandbox Code Playgroud)
小智 0
尝试这个
String title = ((TextView) recyclerView.findViewHolderForAdapterPosition(position).itemView.findViewById(R.id.my_textview)).getText().toString();
Run Code Online (Sandbox Code Playgroud)