Search code examples
seleniumcucumber-junit

How to generate report logs in cucumber-selenium framework


I have use the below code in my testrunner to generate html report in cucumber-selenium framework.

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 {

}

But i have to save each files in the report directory.So how can i create unique report files by concatenating current date&time with the file name.Thanks in advance.


Solution

  • You can do this by adding a runtime shutdown hook in the BeforeClass or AfterClass of the runner.

    @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();
                    }
                  }
                });
        }