// Take screenshot method
static void captureScreenshot(String fileName) throws IOException {
// Take the screenshot and store as file format
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
// Open the current date and time
String timestamp = new SimpleDateFormat("dd_MM_yyyy__hh_mm_ss").format(new Date());
//Copy the screenshot on the desire location with different name using current date and time
Cache.copyFile(scrFile, new File("C:\\Users\\Kiko Kikostov\\IdeaProjects\\AboutPagesBanerScreenSizes\\15inchScreenSize\\Asia\\" + fileName + " " + timestamp + ".png"));
String st = scrFile.getAbsolutePath();
String str = scrFile.getParent();
scrFile = new File(str+"/"+ "/" + fileName);
}
这对我来说很好用,但是我想实现的是,每次运行测试时,都会在现有的文件夹中创建一个新的文件夹或子文件夹。
1条答案
按热度按时间falq053o1#
可以使用
os
创建目录因此,对于您的使用情况,应该是这样的: