使用 Selenium-Cucumber Maven 在每个 运行 上创建单独的报告目录

Create separate report directory on each run using Selenium-Cucumber Maven

我正在使用范围报告在 selenium-cucumber 中生成报告文件。在每个 运行 上,都会通过覆盖先前生成的报告来生成报告。我们如何通过在每个 运行 上附加时间戳来创建单独的报告文件夹。

给出了我正在使用的 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>
<timestamp>${maven.build.timestamp}</timestamp>
 <maven.build.timestamp.format>yyyy_MM_dd_HH_mm</maven.build.timestamp.format>
</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>

如果你们能给出答案,那将非常有帮助。提前致谢

以下代码将生成当前时间戳的字符串对象(您可以将格式更改为任何您喜欢的格式:

String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());

现在,无论您在何处生成范围报告,您都可以在报告名称中传递此字符串。像这样:

extent = new ExtentReports (userDir +"\test-output\" + timeStamp + ".html", true);

奖励积分:

您还可以将地图项名称添加到您的报告中以获得更好的可访问性。您可以在 @Before 挂钩中这样做:

@Before()
    public void beforeScenario(Scenario scenario)
    {
        String fileName = scenario.getName() + "-" + timeStamp;
        extent = new ExtentReports (userDir + \test-output\" + fileName+ ".html", true);
    }

很简单!!!!!!

不要在插件中提及任何文件夹路径 com.cucumber.listener.ExtentCucumberFormatter

示例:

plugin = { 
    "pretty", 
    "html:FeaturesReport",
    "html:target/site/cucumber-pretty",
    "json:target/cucumber.json",

    "com.cucumber.listener.ExtentCucumberFormatter:",
},
  1. 运行项目并刷新

  2. 检查报告将生成在默认文件夹output/Run_with系统time/report.html

如果要在指定路径生成带时间戳的报告,只需按照以下步骤操作即可。

  1. 转到 maven 依赖项

  2. 搜黄瓜-extentsreport.jar

  3. 扩展 jar 和 select com.cucumber.listener

  4. 将整个代码复制到ExtentPropertiesclass

  5. 右键包并创建名称为 ExtentProperties

  6. 的新枚举
  7. 然后在创建的枚举中粘贴ExtentPropertiesclass代码

  8. 搜索以下方法

ExtentProperties() {
    this.reportPath = "output" + File.separator + "Run_" + System.currentTimeMillis() + File.separator + "report.html";
    this.projectName = "default";
}
  1. 并用以下代码替换
String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());

String userDir = System.getProperty("user.dir"); 

ExtentProperties() {
    this.reportPath = "Extent_Reports" + File.separator + "_" + timeStamp.replace(":","_").replace(".","_") + File.separator + "Execution report.html";
    this.projectName = "default";
}
  1. 运行项目然后刷新项目

  2. 检查报告将在指定路径生成名称

Extent_Reports/_2020_06_16_19_14_07/Execution report.html

有问题请评论