我使用Appium来测试使用selenium的Android应用程序。我用了一种方法拍摄了测试病例的截图。一切都很好。图像文件使用SimpleDateFormat以日期格式的名称保存。如果我更改日期格式的模式,它将显示以下错误:
java.io.IOException: The filename, directory name, or volume label syntax is incorrect我的当前模式(运行良好)在代码中是dd-MMM-yyyy__hh_mm_ssaa,它将文件名保存为13-Jul-2017__01_07_01PM.它不是保存在SD卡,而是在我的项目的位置。
我想改名为13-7月-2017_01:01:01:01 PM。
下面是我的截图方法:
public void takeScreenShot() {
String destDir;
DateFormat dateFormat;
// Set folder name to store screenshots.
destDir = "screenshots";
// Capture screenshot.
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
// Set date format to set It as screenshot file name.
dateFormat = new SimpleDateFormat("dd-MMM-yyyy__hh_mm_ssaa");
// Create folder under project with name "screenshots" provided to destDir.
new File(destDir).mkdirs();
// Set file name using current date time.
String destFile = dateFormat.format(new Date()) + ".png";
try {
// Copy paste file at destination folder location
FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));
} catch (IOException e) {
e.printStackTrace();
}
} 我还能用什么图案?
发布于 2017-07-13 09:48:04
尝试这种格式,我使用这种格式来验证我的pass/fail测试用例。
Date d = new Date();
System.out.println(d.toString());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("D:\\RND\\"+sdf.format(d)+".png"));发布于 2017-07-13 09:41:43
首先,看看使用SimpleDateFormat的文档
https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
但是要实现想要的输出,您的模式应该如下所示:
dd-MMM-yyyy_hh:mm:ss aa但据我所知,您不能在文件名中使用:。所以你需要其他的格式
https://stackoverflow.com/questions/45076840
复制相似问题