PS
@Step("Swipe on screen, direction: {0}, times: {1} on platform {2}")
@Override
public void swipeOnScreen(SwipeDirection direction, int times, String platform) {
if (checkPlatform(platform)) {
int[] coordinates = context.helper().getSwipeCoordinates(direction);
swipeOnScreen(coordinates, direction, times);
}
}
public void swipeOnScreen(int[] coordinates, SwipeDirection direction, int times) {
int start_point_x = coordinates[0];
int start_point_y = coordinates[1];
int delta_x = coordinates[2];
int delta_y = coordinates[3];
int end_point_x = start_point_x + delta_x;
int end_point_y = start_point_y + delta_y;
// check if not going out of screen bounds
Dimension screen_size = context.getDriver().manage().window().getSize();
int screen_width = screen_size.width;
if (start_point_x <= 0.0) {
start_point_x = 1;
}
if (end_point_x <= 0.0) {
end_point_x += 1;
}
if (start_point_x >= screen_width) {
start_point_x = screen_width - 1;
}
if (end_point_x >= screen_width) {
end_point_x = screen_width - 1;
}
TouchAction swipe = new TouchAction(context.getDriver());
while (times > 0) {
swipe
.press(PointOption.point(start_point_x, start_point_y))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000)))
.moveTo(PointOption.point(end_point_x, end_point_y))
.release()
.perform();
log.info("Swipe {} ({}, {}) -> ({}, {})",
direction,
start_point_x,
start_point_y,
end_point_x,
end_point_y);
times -= 1;
}
}