如何在 cucumber-selenium 框架中生成报告日志

How to generate report logs in cucumber-selenium framework

我在我的测试运行器中使用以下代码在 cucumber-selenium 框架中生成 html 报告。

package selenium_cucumber_project_pkg;
import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;

 @RunWith(Cucumber.class)
 @Cucumber.Options(
               features="features",
               glue= {"stepdefinition"},
               format={"pretty", "html:report/cucumber-html-report"}  
              )

public class testrunner {

}

但我必须将每个文件保存在报告中 directory.So 我如何通过提前将当前日期和时间与文件 name.Thanks 连接来创建唯一的报告文件。

您可以通过在运行器的 BeforeClassAfterClass 中添加运行时关闭挂钩来实现。

@AfterClass
    public static void after() {
        Runtime.getRuntime().addShutdownHook(new Thread()
        {
              public void run()
              {         
                try {
                    Files.move(Paths.get("report"), Paths.get("report - "+ 
                LocalDateTime.now().format(DateTimeFormatter.ofPattern("L-d-YYYY H-m-s"))), 
                            StandardCopyOption.REPLACE_EXISTING);
                } catch (IOException e) {
                    e.printStackTrace();
                }
              }
            });
    }