Жесткое кодирование местоположений x и y - не лучшая идея, но если вы хотите провести пальцем по горизонтали, точки y должны быть одинаковыми. Они на 20 пикселей в вашем примере. Однако, вероятно, это не повлияет на результат.
Вот мой метод прокрутки / прокрутки:
/**
* 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
*/
@SuppressWarnings("rawtypes")
public void scroll(int startx, int starty, int endx, int endy) {
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(PointOption.point(startx, starty))
.waitAction(WaitOptions.waitOptions(ofSeconds(1)))
.moveTo(PointOption.point(endx, endy))
.release()
.perform();
}
Теперь у меня есть другие методы, которые используют экранные координаты, чтобы определить, какими должны быть x и y, и затем вызываем метод прокрутки, например:
/**
* This method does a swipe right
* @author Bill Hileman
*/
public void swipeRight() {
//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);
}