生成Selenium Cucumber报告而不覆盖以前的Maven测试输出结果吗?

时间:2018-08-21 13:00:36

标签: java maven selenium junit cucumber

我需要在每次运行的报告目录中分别保存每个报告文件。如何通过将当前日期和时间与文件名串联在一起来创建报告文件。 我已经在TestRunnerTest.java中使用以下代码在黄瓜硒框架中生成Extentreport。

package testRunner;

import java.io.File;
import java.io.IOException;
import java.nio.file.StandardCopyOption;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.TimeUnit;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.vimalselvam.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(

    features = "src/test/resources"
            , glue= {"stepDefinition"}
    , plugin = { "com.vimalselvam.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"}, 
            monochrome = true
    )
public class TestRunnerTest {
public static WebDriver driver;
private static TestRunnerTest sharedInstance = new TestRunnerTest();

 private TestRunnerTest() { }

 public static TestRunnerTest getInstance() {
        return sharedInstance;
    }

 @BeforeClass
    public static void before() {   

           System.setProperty("webdriver.chrome.driver", 
"E:\\ChromeDriverNew\\chromedriver.exe");
           driver=new ChromeDriver();

           driver.manage().window().maximize();
 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);   
    }
 @AfterClass
    public static void after() {

     Reporter.loadXMLConfig(new File("config/report.xml"));  
     driver.quit();
    }
}

这是我的POM依赖文件。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>selcuc</groupId>
  <artifactId>DemoEurasia</artifactId>
  <version>0.0.1-SNAPSHOT</version>

<properties>
<version.cucumber>3.0.2</version.cucumber>
</properties>
  <dependencies>
 <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
 </dependency>   
 <dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.14.0</version>
</dependency>   
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>provided</scope>
</dependency>
 <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
</dependency>   
<dependency> 
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
</dependency>   
<dependency> 
    <groupId>info.cukes</groupId> 
    <artifactId>gherkin</artifactId> 
    <version>2.12.2</version> 
</dependency>   
<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>3.1.5</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>com.vimalselvam</groupId>
    <artifactId>cucumber-extentsreport</artifactId>
    <version>3.1.1</version>
</dependency>

   <build>
    <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
               <encoding>UTF-8</encoding>          
            </configuration>
          </plugin>  
          <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>2.17</version>
    </plugin>                                        
    </plugins>
</build>

任何人都可以回答如何使用Selenium-Cucumber Maven Framework在每次执行中生成报告日志。预先感谢

3 个答案:

答案 0 :(得分:0)

您可以实现自己的黄瓜Plugin,该黄瓜装饰ExtentCucumberFormatter并使用其他文件名对其进行初始化。看看现有的插件,以获取有关如何执行此操作的提示。

答案 1 :(得分:0)

我不确定您是否有解决方案,但是下面有两种方法可以解决。

1。将tetsRunner.java文件中的plugin的值设置为ExtentCucumberFormatter,即,plugin = {“ com.cucumber.listener.ExtentCucumberFormatter:”}并执行tetscase。默认情况下,此报告将在项目目录的Output文件夹下创建(只需从Project Explorer刷新项目,就会生成output文件夹)

  1. 设置动态输出文件的路径,例如在@BeforeClass Hooker中设置如下,在testRunner文件中。

    @CucumberOptions(
    features = "src/test/java/Features"
    ,glue= {"StepDefinations"}
    ,plugin = { "com.cucumber.listener.ExtentCucumberFormatter:"}
    ,monochrome = true
    )
    public class testRunner {
    @BeforeClass
    public static void setup() {
    ExtentProperties extentProperties = ExtentProperties.INSTANCE;
    String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
    String userDir =System.getProperty("user.dir"); 
    extentProperties.setReportPath(userDir+ 
                                 "/target/cucumberreports/report_"+timeStamp+".html");
    }
    }
    

答案 2 :(得分:0)

在您的POM(插件部分)中,您可以执行以下操作:

    <configuration>
         <sourceJsonReportDirectory>${project.build.directory}/cucumber-report</sourceJsonReportDirectory>
         <generatedHtmlReportDirectory>${project.build.directory}/generated-report/cluecumber_report_${maven.build.timestamp}</generatedHtmlReportDirectory>
</configuration>

使用Maven.build.timestamp将生成带有日期戳的文件夹(UTM 00:00)