Appium + java截图方法

时间:2023-01-25 16:16:45
    public static void takeScreenShot(AndroidDriver<WebElement> driver)
{
File screenShotFile = driver.getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(screenShotFile, new File("D:\\AutoScreenCapture\\" + getCurrentDateTime()+ ".jpg"));
}
catch (IOException e) {e.printStackTrace();}
}
public static String getCurrentDateTime(){
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss");//设置日期格式
return df.format(new Date());
}

方法引用:

takeScreen.takeScreenShot(driver);