The following code sample uses the driver's getScreenshotAs method that captures a screenshot of the device and then FileUtils.copyFile to copy the screenshot to a local file.


File file  = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("Screenshot.jpg"));

On running this code, you will find a Screenshot.jpg file in the root folder of your Appium project. You can also specify a directory of your choice as the copyFile method’s parameter, for example:

File file  = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File("C:/temp/Screenshot.jpg"));