In espresso, some times the swipe functionality not works like for “Swipeleft”, “swiperight”,”swipeup”,”swipedown”,”swipeup”.
so for this problem we can create a custom swipe to swipe up , down , left and right.
1. Swipe Up :-
Swipe up used to custom swipe the page upward using the id of any element.
1 |
public static ViewAction customswipeUp() {return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.BOTTOM_CENTER,GeneralLocation.TOP_CENTER, Press.FINGER);} |
usage:-
1 |
onView(withId(R.id. element_id).perform(customswipeUp()); |
2. Swipe Down :-
Swipe down used to custom swipe the page downward direction using the id of any element.
1 |
public static ViewAction customswipeDown() {return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.TOP_CENTER,GeneralLocation.BOTTOM_CENTER, Press.FINGER);} |
usage :-
1 |
onView(withId(R.id. element_id)).perform(customswipeDown()); |
3. Swipe Left :-
Swipe left used to custom swipe the page leftward direction using the id of any element.
1 |
public static ViewAction customswipeLeft() {return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.CENTER_RIGHT,GeneralLocation.CENTER_LEFT, Press.FINGER);} |
usage :-
1 |
onView(withId(R.id. element_id)).perform(customswipeLeft()); |
4. Swipe Right :-
Swipe left used to custom swipe the page rightward direction using the id of any element.
1 |
public static ViewAction customswipeRight() {return new GeneralSwipeAction(Swipe.FAST, GeneralLocation.CENTER_LEFT,GeneralLocation.CENTER_RIGHT, Press.FINGER);} |
usage :-
1 |
onView(withId(R.id. element_id)).perform(customswipeRight()); |
So in this way, we can create a custom swipe approach in espresso when the swipe doesn’t work.
Hope this blog will help you.
Thanks for reading : )