Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Espresso: How to do custom swipe e.g. swipeTop or swipeBottom

So far we can do:

  • swipeLeft
  • swipeRight
  • swipeUp
  • swipeDown

How can we swipeTop(all the way to the Top) or swipeBottom(all the way to the bottom) is expresso. Please give me an example if these methods already exists.

like image 653
testsingh Avatar asked Jan 29 '15 15:01

testsingh


2 Answers

Have you tried a GeneralSwipeAction like that?

private static ViewAction swipeFromTopToBottom() {
    return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER,
            GeneralLocation.BOTTOM_CENTER, Press.FINGER);
}

Maybe you have to provide a custom implementation for the second and/or third parameter, as Anna already mentioned:

new CoordinatesProvider() {
    @Override
    public float[] calculateCoordinates(View view) {
        float[] coordinates =  GeneralLocation.CENTER.calculateCoordinates(view);
        coordinates[1] = 0;
        return coordinates;
    }
}
like image 136
Alexander Pacha Avatar answered Sep 23 '22 06:09

Alexander Pacha


For example if you use recyclerView in yours application, you can use something like this:

Espresso.onView(ViewMatchers.withId(R.id.recyclerView)).perform(ViewActions.swipeUp())

or

Espresso.onView(ViewMatchers.withId(R.id.recyclerView)).perform(ViewActions.swipeDown())
like image 44
Morozov Avatar answered Sep 22 '22 06:09

Morozov