Espresso 在 RecyclerView 中发现可能不在屏幕上的行
Espresso finding row in RecyclerView that could be off screen
我有一个 RecyclerView,它可以包含任意数量的项目。我需要能够从该列表中获取一行,以便我可以检查其内容或 click/long 单击该行。
我正在努力弄清楚如何做到这一点,因为与 ListView "onData" 不同,没有内置功能可以滚动 RecyclerView 来查找行。如果使用 RecyclerView,如果视图实际上不在屏幕上,您似乎无法验证行 UI.
在我看到的示例中,他们使用列表中的项目数滚动到每一行。但是我事先不知道我的列表有多少行,因为数字不固定。
这个解决方案看起来很有前途,但前提是您知道列表中要传递给 espresso 对象的项目,这对我不适用。
https://medium.com/@_rpiel/recyclerview-and-espresso-a-complicated-story-3f6f4179652e
同样这个例子知道要移动到哪一行
http://blog.forkingcode.com/2016/06/espresso-and-recyclerview.html
我需要做类似
的事情
onView(withId(R.id.recyclerView)).perform(findRowWhichHasText("name1");
其中 "findRowWhichHasText" 做类似
的事情
- 查找列表中的项目数
- 依次滚动到每一个 (scrollToPosition(i) )
检查该行是否有我想要的项目。像
StringUtils.equals(viewHolder.nameView.getText().toString(), assetName);
我在这个 wiki 页面中找到了解决方案。
http://alexander-thiele.blogspot.com/2016/01/espresso-ui-tests-and-recyclerview.html
他的代码onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollToHolder(withHolderTimeView(getActivity().getString(R.string.all_day_event))));
其中 withHolderTimeView 是一个匹配器,它将 Viewholder 与您要查找的项目相匹配。
我有一个 RecyclerView,它可以包含任意数量的项目。我需要能够从该列表中获取一行,以便我可以检查其内容或 click/long 单击该行。
我正在努力弄清楚如何做到这一点,因为与 ListView "onData" 不同,没有内置功能可以滚动 RecyclerView 来查找行。如果使用 RecyclerView,如果视图实际上不在屏幕上,您似乎无法验证行 UI.
在我看到的示例中,他们使用列表中的项目数滚动到每一行。但是我事先不知道我的列表有多少行,因为数字不固定。
这个解决方案看起来很有前途,但前提是您知道列表中要传递给 espresso 对象的项目,这对我不适用。
https://medium.com/@_rpiel/recyclerview-and-espresso-a-complicated-story-3f6f4179652e
同样这个例子知道要移动到哪一行 http://blog.forkingcode.com/2016/06/espresso-and-recyclerview.html
我需要做类似
的事情onView(withId(R.id.recyclerView)).perform(findRowWhichHasText("name1");
其中 "findRowWhichHasText" 做类似
的事情- 查找列表中的项目数
- 依次滚动到每一个 (scrollToPosition(i) )
检查该行是否有我想要的项目。像
StringUtils.equals(viewHolder.nameView.getText().toString(), assetName);
我在这个 wiki 页面中找到了解决方案。 http://alexander-thiele.blogspot.com/2016/01/espresso-ui-tests-and-recyclerview.html
他的代码onView(withId(R.id.recyclerView)).perform(RecyclerViewActions.scrollToHolder(withHolderTimeView(getActivity().getString(R.string.all_day_event))));
其中 withHolderTimeView 是一个匹配器,它将 Viewholder 与您要查找的项目相匹配。