Click and Hold touch action in Appium


#1

I want to click and hold the object then take a screen shot before releasing the object, is it possible in Appium ?.


#2

Yes, it is possible.

Appium version : 1.8.1
Java client : 6.1.0

public void longPressScreenshot(MobileElement element,String screenshotName){
new TouchAction<>(driver).longPress(longPressOptions()
.withElement(element(element))).waitAction(waitOptions(Duration.ofSeconds(3)))
.moveTo(ElementOption.element(element))
.perform().release();
captureScreenshot(screenshotName);
}

public void captureScreenshot(String screenshotName) {
File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String filePath = System.getProperty(“user.dir”) + File.separator + “screenshots” + File.separator +screenshotName+".png";
try {
FileUtils.copyFile(srcFile, new File(filePath));
} catch (IOException e) {
e.printStackTrace();
}
}

com-video-to-gif


#3

Is this possible to do in Python?