【问题标题】:Creating folder and sub folder where sub folder should be created one beside another in java在java中创建文件夹和子文件夹,其中子文件夹应在另一个旁边创建
【发布时间】:2017-01-27 06:10:13
【问题描述】:

我在创建文件夹时遇到了问题。请在下面找到我的要求

  1. 每次运行测试时,都会创建一个带有时间戳的新文件夹。
  2. 在时间戳文件夹下,应该创建另一个文件夹。例如,
  3. 在此子文件夹下,新文件夹应并排创建,并且不允许重复。

试试 - 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() 方法,而不是在另一个旁边创建子文件夹,而是在文件夹内创建文件夹)

前: 公共无效测试(){ screenshot_TestCaseFolder(); screenshot_TestCaseFolder(); screenshot_TestCaseFolder(); }

请帮我解决这个问题

提前致谢

【问题讨论】:

    标签: selenium-webdriver appium-ios


    【解决方案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();
    
        }
    
        //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();
    
        }
    

    【讨论】:

      猜你喜欢
      • 2018-12-02
      • 2020-07-18
      • 2022-01-21
      • 2012-06-03
      • 2019-11-24
      • 2018-08-09
      • 2020-06-05
      • 1970-01-01
      • 2014-01-17
      相关资源
      最近更新 更多