我已经使用以下脚本拍摄了appium测试的屏幕截图。
String path;
try {
WebDriver augmentedDriver = new Augmenter().augment(driver);
File source = ((TakesScreenshot)augmentedDriver).getScreenshotAs(OutputType.FILE);
path = "/Users/admin/Desktop/newfolder" + source.getName();
org.apache.commons.io.FileUtils.copyFile(source, new File(path));
}
catch(IOException e) {
path = "Failed to capture screenshot: " + e.getMessage();
}
我想将它们带到以timestamp命名的文件夹中。
如何在appium测试期间提供文件夹路径以保存这些屏幕截图?
答案 0 :(得分:2)
尝试此操作以创建具有时间戳名称的文件夹: String.valueOf(new Timestamp(System.currentTimeMillis()))。replace(":"," - ")
答案 1 :(得分:0)
添加" /"在" newfolder"之后当您设置path =
以使其成为
path = "/Users/admin/Desktop/newfolder/" + source.getName();
考虑到The N…的答案,应该创建路径,如:
String timestampAsString = String.valueOf(new Timestamp(System.currentTimeMillis())).replace(":", "-");
path = "/Users/admin/Desktop/" + timestampAsString + "/" + source.getName();