对于每个执行屏幕截图应保存在带有日期和时间的不同文件夹中。尝试使用下面的代码,但它没有按预期工作。它是基于分钟而不是执行生成文件夹。请帮助..提前致谢。
public static String screenShot(WebDriver driver,
String screenShotName, String testName) {
Calendar calendar = Calendar.getInstance();
SimpleDateFormat formater = new SimpleDateFormat("dd_MM_yyyy_hh_mm_ss");
SimpleDateFormat formater1 = new SimpleDateFormat("dd_MM_yyyy_hh_mm");
try {
File screenshotFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
File targetFile = new File("iWealthHKTestAutomation/resources/Screenshots_"+formater1.format(calendar.getTime())+"/"+ screenShotName+formater1.format(calendar.getTime()) + ".png");
FileUtils.copyFile(screenshotFile, targetFile);
return screenShotName;
} catch (Exception e) {
System.out.println("An exception occured while taking screenshot " + e.getCause());
return null;
}
}
public String getTestClassName(String testName) {
String[] reqTestClassname = testName.split("\\.");
int i = reqTestClassname.length - 1;
System.out.println("Required Test Name : " + reqTestClassname[i]);
return reqTestClassname[i];
}
慕标5832272
相关分类