如何在不覆盖之前的测试结果的情况下生成测试报告

How to generate testng report without overwritng the previous test result

我正在使用 Selenium 和 Java 自动化 Web 应用程序。

我正在并行执行多个 testng xml 文件,所以结果每次都会被覆盖。

例如:我有两个 xml 文件(testng1.xml 和 testng 2.xml)。当我 运行 这两个文件并行时,来自 testng2.xml 的结果在可通过电子邮件发送的报告中被 testng1.xml 覆盖。

如何为每个 xml 文件生成单独的报告?

我使用下面的代码实现了这个场景。

public String xmlString;

public int xmlIndex;

public String folderName;

public String locationName;

public static String reportName = "emailable-report.html";

    xmlString = <list of xml files>;
    xmlIndex = xmlString.lastIndexOf("/");
    locationName = xmlString.substring(xmlIndex+1);
    folderName = locationName.replace(".xml", "").toUpperCase();

File dir = new File("Result"); // Here I am creating a common folder and the sub folders will be created as per the xml file executions.
    if(dir.exists())
    {
        try {
            FileUtils.deleteDirectory(dir);
        } catch (IOException e) {
            e.printStackTrace();
        }
        dir.mkdir();
    }
    else
    {
        dir.mkdir();
    }
    String xmlFolderPath = System.getProperty("user.dir") +"/"+ dir + "/"+ folderName;
    testng.setOutputDirectory(xmlFolderPath);
    File resultFile = new File(System.getProperty("user.dir") +"/"+ dir + "/" +"ResultFiles"); // In this folder only testng result (.html)files are moved here.
    resultFile.mkdir();


File folder = new File(xmlFolderPath); // In this folder, separate sub folders were created according to the xml files and the sub folder will be the xml file names. 
     File[] listOfFiles = folder.listFiles();

        for (int i = 0; i < listOfFiles.length; i++)
        {
          if (listOfFiles[i].isFile())
          {                   
              if(reportName.equalsIgnoreCase("emailable-report.html"))       
              {                   
                  Path src = Paths.get(xmlFolderPath + "/" + reportName);
                  Path desc = Paths.get(resultFile + "/" + folderName + ".html"); // Here emailable-report.html is renamed according to the XML file name and moved to this folder
                  try
                  {
                    Files.move(src, desc, StandardCopyOption.REPLACE_EXISTING);
                    System.out.println(src.resolveSibling(folderName + ".html"));
                    break;
                  } 
                  catch (IOException e) 
                  {
                    System.out.println(e);
                  }
             }
              else
              {
                  System.out.println("Expected file not present in the specified folder..!!!");
              }
          }
        }