Along with Dmitri’s strategies, you too can use TouchActions, as I do in my code:
/**
* This technique scrolls based mostly upon the handed parameters
* @writer Invoice Hileman
* @param int startx - the beginning x place
* @param int starty - the beginning y place
* @param int endx - the ending x place
* @param int endy - the ending y place
*/
@SuppressWarnings("rawtypes")
public void scroll(int startx, int starty, int endx, int endy) {
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(PointOption.level(startx, starty))
.moveTo(PointOption.level(endx, endy))
.launch()
.carry out();
}
/**
* This technique does a swipe upwards
* @writer Invoice Hileman
*/
public void scrollDown() {
//The viewing dimension of the gadget
Dimension dimension = driver.handle().window().getSize();
//Beginning y location set to 80% of the peak (close to backside)
int starty = (int) (dimension.peak * 0.80);
//Ending y location set to twenty% of the peak (close to high)
int endy = (int) (dimension.peak * 0.20);
//x place set to mid-screen horizontally
int startx = (int) dimension.width / 2;
scroll(startx, starty, startx, endy);
}
/**
* This technique does a swipe left
* @writer Invoice Hileman
*/
public void swipeLeft() {
//The viewing dimension of the gadget
Dimension dimension = driver.handle().window().getSize();
//Beginning x location set to 95% of the width (close to proper)
int startx = (int) (dimension.width * 0.95);
//Ending x location set to five% of the width (close to left)
int endx = (int) (dimension.width * 0.05);
//y place set to mid-screen vertically
int starty = dimension.peak / 2;
scroll(startx, starty, endx, starty);
}
/**
* This technique does a swipe proper
* @writer Invoice Hileman
*/
public void swipeRight() {
//The viewing dimension of the gadget
Dimension dimension = driver.handle().window().getSize();
//Beginning x location set to five% of the width (close to left)
int startx = (int) (dimension.width * 0.05);
//Ending x location set to 95% of the width (close to proper)
int endx = (int) (dimension.width * 0.95);
//y place set to mid-screen vertically
int starty = dimension.peak / 2;
scroll(startx, starty, endx, starty);
}
/**
* This technique does a swipe downwards
* @writer Invoice Hileman
*/
public void scrollUp() {
//The viewing dimension of the gadget
Dimension dimension = driver.handle().window().getSize();
//Beginning y location set to twenty% of the peak (close to backside)
int starty = (int) (dimension.peak * 0.20);
//Ending y location set to 80% of the peak (close to high)
int endy = (int) (dimension.peak * 0.80);
//x place set to mid-screen horizontally
int startx = dimension.width / 2;
scroll(startx, starty, startx, endy);
}