Report 如何避免区段报告不覆盖html文件名

Report 如何避免区段报告不覆盖html文件名,report,extentreports,extent,Report,Extentreports,Extent,我在appium中与testng一起使用扩展报告,它对我来说工作正常。当我的测试运行完成后,扩展报告将在我的项目文件夹中生成html文件,这就是预期的结果 问题是,当我再次运行测试时,扩展报告会通过过度加载以前创建的html文件的名称来生成新的html报告文件 我希望“扩展数据块报告”生成具有唯一名称的html文件,或在中包含日期的名称,每次运行测试时,您都可以将文件名创建为当前时间戳。这样,报告文件就很容易有一个唯一的名称- String timeStamp = new SimpleDateF

我在appium中与testng一起使用扩展报告,它对我来说工作正常。当我的测试运行完成后,扩展报告将在我的项目文件夹中生成html文件,这就是预期的结果

问题是,当我再次运行测试时,扩展报告会通过过度加载以前创建的html文件的名称来生成新的html报告文件


我希望“扩展数据块报告”生成具有唯一名称的html文件,或在中包含日期的名称,每次运行测试时,您都可以将文件名创建为当前时间戳。这样,报告文件就很容易有一个唯一的名称-

String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
extent = new ExtentReports (userDir +"\\test-output\\" + timeStamp + ".html", true);

您可以通过设置唯一名称来执行此操作:

String reportFile = resultDirectory + fileName + ".html";
用于将报告保存到特定文件夹的方法:

public void saveReportFolder() throws IOException { 
     File srcDir = new 
     File(System.getProperty("user.home")+"/Automation/target"); 
     File destDir = new File(System.getProperty("user.home") + "/reports/"+ System.getProperty("user.name")+"/"+dateTimeGenerator()); 
     FileUtils.copyDirectory(srcDir, destDir); 
}
…和用于设置日期时间的实用程序:

public static String dateTimeGenerate(){
    Format formatter = new SimpleDateFormat("YYYYMMdd_HHmmssSSS");
    Date date = new Date(System.currentTimeMillis());
   return formatter.format(date);
}
或者简单地使用启动服务器并将所有内容都放在数据库中(MongoDb),这是一种更优雅的方式

希望这有帮助,我使用:

private static String timestamp = new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime()).replaceAll(":", "-");
public static String reportFullPath = getReportsPath() + "\\AutomationReport_" + timestamp + ".html";

我就是这样做的,简单又爽快

String Outputfilename= ExecutionConfig.FileOutname;
        System.err.close(); // written to remove JAVA 9 incompatibility.. continued below
        System.setErr(System.out); // continue.. and remove the warnings
        extent = new ExtentReports(System.getProperty("user.dir") + "/test-output/"+Outputfilename+".html", true);
因此,这里从ExecutionConfig类调用ExecutionConfig.FileOutname,我在这里读取config.properties文件中的值。然后在这里将其分配给输出文件


它也对我起了作用。

我也面临着类似的问题。在现实世界中,我们也需要旧的报告。下面是用于扩展PDF报告的Java解决方案

我添加了一个事件侦听器方法。已使用事件-TestRunStarted。我们还需要注册参加这次活动。该解决方案也可以用于HTML报告

public void setCustomReportName(TestRunStart事件)
{
最终SimpleDataFormat sdf=新SimpleDataFormat(“yyyy.MM.dd.HH.MM.ss”);
Timestamp Timestamp=新的时间戳(System.currentTimeMillis());
字符串currenttimestamp=sdf.format(时间戳);
Properties prop=新属性();
//extent.reporter.pdf.out是表示报告路径的属性的名称
prop.setProperty(“extent.reporter.pdf.out”,“测试输出/PdfReport/ExtentPdf_”+currenttimestamp+”.pdf”);
ExtentService e1=新的ExtentService();
//ExtentReportsLoader是ExtentService的内部类,initPdf是它的私有方法,它采用报告的路径
类[]a=e1.getClass().getDeclaredClasses();
方法met;
//即使出现异常,测试运行也不会失败,并将生成报告(ExtentPdf.pdf)
试一试{
met=a[0].getDeclaredMethod(“initPdf”,Properties.class);
met.setAccessible(true);
met.invoke(a[0],prop);
}捕获(无此方法例外){
System.out.println(“没有名为initPdf的方法”);
}捕获(安全异常e){
e、 printStackTrace();
}捕获(非法访问例外e){
e、 printStackTrace();
}捕获(IllegalArgumentException e){
System.out.println(“传递给initPdf方法的参数不正确”);
}捕获(调用TargetException e){
e、 printStackTrace();
}
}

您每次都可以传递一个唯一的文件名。如果您在原始帖子中显示了部分代码,或者至少说明了您使用的语言,这会有所帮助。