0

I am working on an app where the devs have created an endless circular recycler view. While using the app, you can scroll through the recycler view endlessly. For that, you have to click on any item on the recycler view and scroll. Once you see desired item on the screen, you have to leave your finger, and as soon as you leave your finger, the screen background changes color and a corresponding button is shown on the screen. Now, This is where I face an issue with.

I have used Espresso and Barista libraries to scroll thru the list and I am succeeded in scrolling. I used following code to scroll:

Barista libraries:

scrollListToPosition(R.id.recyclerview, 5);

clickListItem(R.id.recyclerview, 6);

Also, Espresso libraries:

onView(withId(R.id.content_view)).perform(RecyclerViewActions.scrollToPosition(5));

With both the above methods, I am able to scroll through the list and the correct item appears on the screen, but the background color is not changed and the corresponding button is not shown on the screen. (If I compare this behavior with an actual device, this happens when I swipe up with my finger but do not leave the finger on the screen. And as soon as I leave the finger, the color changes and a button appears) So, in short, i am able to scroll but not able to mimic the behavior of leaving the finger from the screen.

touhid udoy
  • 4,005
  • 2
  • 18
  • 31
Amit Jathar
  • 319
  • 3
  • 14

2 Answers2

0

With Espresso, you can use RecyclerViewActions.actionOnItemAtPosition and perform a long click to have the effect of leaving the finger:

onView(withId(R.id.content_view)).perform(RecyclerViewActions.actionOnItemAtPosition(5, longClick()));
paulajcm
  • 192
  • 2
  • 11
  • It gives same the result. It scrolled to the 5th element but does not click. As the app wants=> touch finger + scroll to desired element + release finger. I think, we can just scroll but not sure how the touch and release before scroll can be mimicked. – Amit Jathar Jan 19 '19 at 22:24
  • Have you tried a custom swipe? I haven't tried, but this might give the result you want. This answer has an example of implementation: https://stackoverflow.com/a/32933907/6266427 – paulajcm Jan 20 '19 at 18:54
  • I tried the GeneralSwipeAction, but it didn't help. I am able to find the working code as I have posted above. – Amit Jathar Jan 24 '19 at 05:27
0

I found an answer to the above question. The click and scroll has to be performed back to back, like a drag and drop:

onView(withId(R.id.recycler_view)).perform(actionOnItemAtPosition(0, longClick()));

onView(withId(R.id.recycler_view)).perform(actionOnItemAtPosition(1, swipeUp()));

With this code, I long click on the 0th element and then swipe up to the 1st element.

Amit Jathar
  • 319
  • 3
  • 14