Я был уверен, что опубликовал это в прошлом и не хотел повторно публиковать его, но я не могу найти его, поэтому я публикую здесь сейчас.
Ниже приведен наборметоды, которые позволят вам прокручивать вверх, вниз, влево и вправо, с предшествующим суммарным (универсальным) методом прокрутки, вызываемым каждым из предыдущих четырех методов направленной прокрутки.
/**
* This method scrolls based upon the passed parameters
* @author Bill Hileman
* @param int startx - the starting x position
* @param int starty - the starting y position
* @param int endx - the ending x position
* @param int endy - the ending y position
*/
public void scroll(int startx, int starty, int endx, int endy) {
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(PointOption.point(startx, starty))
.moveTo(PointOption.point(endx, endy))
.release()
.perform();
}
/**
* This method does a swipe upwards
* @author Bill Hileman
* @throws Exception
*/
public void scrollDown() throws Exception {
//The viewing size of the device
Dimension size = driver.manage().window().getSize();
//Starting y location set to 80% of the height (near bottom)
int starty = (int) (size.height * 0.80);
//Ending y location set to 20% of the height (near top)
int endy = (int) (size.height * 0.20);
//x position set to mid-screen horizontally
int startx = (int) size.width / 2;
scroll(startx, starty, startx, endy);
}
/**
* This method does a swipe left
* @author Bill Hileman
* @throws Exception
*/
public void swipeLeft() throws Exception {
//The viewing size of the device
Dimension size = driver.manage().window().getSize();
//Starting x location set to 95% of the width (near right)
int startx = (int) (size.width * 0.95);
//Ending x location set to 5% of the width (near left)
int endx = (int) (size.width * 0.05);
//y position set to mid-screen vertically
int starty = size.height / 2;
scroll(startx, starty, endx, starty);
}
/**
* This method does a swipe right
* @author Bill Hileman
* @throws Exception
*/
public void swipeRight() throws Exception {
//The viewing size of the device
Dimension size = driver.manage().window().getSize();
//Starting x location set to 5% of the width (near left)
int startx = (int) (size.width * 0.05);
//Ending x location set to 95% of the width (near right)
int endx = (int) (size.width * 0.95);
//y position set to mid-screen vertically
int starty = size.height / 2;
scroll(startx, starty, endx, starty);
}
/**
* This method does a swipe downwards
* @author Bill Hileman
* @throws Exception
*/
public void scrollUp() throws Exception {
//The viewing size of the device
Dimension size = driver.manage().window().getSize();
//Starting y location set to 20% of the height (near bottom)
int starty = (int) (size.height * 0.20);
//Ending y location set to 80% of the height (near top)
int endy = (int) (size.height * 0.80);
//x position set to mid-screen horizontally
int startx = size.width / 2;
scroll(startx, starty, startx, endy);
}