我在文件夹创建中遇到问题。请在下面找到我的要求
尝试 - 1
public static File outputFile;
public static void screenshot_TimeStamp_Language_Folder(String language){
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
outputFile = new File(timeStamp+"./L"+"_"+language);
outputFile.mkdir();
System.out.println(outputFile);
}
public static void screenshot_TestCaseFolder(String testCaseFolderName){
String st = outputFile.getAbsolutePath();
outputFile = new File(st+"./xyz_"+testCaseFolderName);
outputFile.mkdir();
System.out.println(outputFile);
}
public static void CaptureScreen(AppiumDriver driver, String imageFileName)
{
File scrFile = driver.getScreenshotAs(OutputType.FILE);
//String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
String path = outputFile.getAbsolutePath();
System.out.println(path);
File outputFile = new File(path + "/" + imageFileName +".jpg");
try {
FileUtils.copyFile(scrFile, outputFile);
}
catch (IOException ex) {
System.out.println(Level.SEVERE + " Failed to save screen shot to " + outputFile);
}
}
但是我在第三步失败了(如果你在同一个执行中多次调用screenshot_TestCaseFolder()方法,而不是在另一个文件夹中创建子文件夹而不是创建子文件夹)
EX: public void test(){ screenshot_TestCaseFolder(); screenshot_TestCaseFolder(); screenshot_TestCaseFolder(); }
请帮我解决这个问题
提前致谢
答案 0 :(得分:0)
我找到了解决方案
public static File outputFile;
public static void screenshot_TimeStamp_Language_Folder(String language){
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
outputFile = new File(timeStamp+"./L"+"_"+language);
outputFile.mkdir();
}
//This is for first time folder creation
public static void screenshot_TestCaseFolder(String testCaseFolderName){
String st = outputFile.getAbsolutePath();
outputFile = new File(st+"./ANMM_"+testCaseFolderName);
outputFile.mkdirs();
}
//This is for second time folder creation
public static void screenshot_TestCaseFolder1(String sample){
String st = outputFile.getAbsolutePath();
System.out.println("The first path is"+st);
String str = outputFile.getParent();
System.out.println("The second path is"+str);
outputFile = new File(str+"/"+"/"+sample);
//outputFile = new File(st+"./ANMM_" + "/" +testCaseFolderName);
outputFile.mkdirs();
}