我有可能包含任何数量的项目的RecyclerView。我需要能够从该列表中得到一个排,所以我可以检查它的内容,或点击/长按该行上。
我奋力大大弄清楚如何做到这一点的不同ListView的“昂达”有没有内置的功能,通过RecyclerView滚动才能找到该行。看来,与RecyclerView如果视图实际上不是ON SCREEN你无法验证行UI。
在这些例子中我看到他们正在使用列表中的项目数量滚动到每一行。但是我不知道事先我的名单多少行具有与数量是不固定的。
该解决方案看起来非常有前途的,但假设你知道在你的列表中的项目通入咖啡对象这并不适用于我。
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”确实有点像
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))执行(RecyclerViewActions.scrollToHolder(withHolderTimeView(getActivity()的getString(R.string.all_day_event))))。;
凡withHolderTimeView是其中Viewholder匹配您正在寻找的项目匹配。