use of io.appium.java_client.MobileDriver in project carina by qaprosoft.
the class MobileUtils method swipe.
/**
* Swipe by coordinates using TouchAction (platform independent)
*
* @param startx int
* @param starty int
* @param endx int
* @param endy int
* @param duration int Millis
*/
public static void swipe(int startx, int starty, int endx, int endy, int duration) {
LOGGER.debug("Starting swipe...");
WebDriver drv = DriverPool.getDriver();
LOGGER.debug("Getting driver dimension size...");
Dimension scrSize = drv.manage().window().getSize();
LOGGER.debug("Finished driver dimension size...");
// explicitly limit range of coordinates
if (endx > scrSize.width) {
LOGGER.warn("endx coordinate is bigger then device width! It will be limited!");
endx = scrSize.width - 1;
} else {
endx = Math.max(1, endx);
}
if (endy > scrSize.height) {
LOGGER.warn("endy coordinate is bigger then device height! It will be limited!");
endy = scrSize.height;
} else {
endy = Math.max(1, endy);
}
LOGGER.info("startx: " + startx + "; starty: " + starty + "; endx: " + endx + "; endy: " + endy + "; duration: " + duration);
new TouchAction((MobileDriver<?>) drv).press(startx, starty).waitAction(Duration.ofMillis(duration)).moveTo(endx, endy).release().perform();
LOGGER.debug("Finished swipe...");
}
Aggregations