我尝试了很多选项来生成Cucumber + Java + Maven + Junit的扩展报告,但是它没有生成扩展报告。下面是我的代码:
下面是我的Pom.xml文件:
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>3.3.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.10.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-jvm -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.2.5</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>3.10.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.10.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
<!-- Cucumber Gherkin SYNTAX -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
</dependency>
<!-- 1st is for Cucumber Extent advance Reporting -->
<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.5</version>
</dependency>
</dependencies>
also plugins from pom.xml
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<fork>true</fork>
<executable>C:\Program Files\Java\jdk1.8.0_66\bin\javac.exe</executable>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.20</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<!-- <include>**/*Runner.java</include> -->
<!-- <exclude>**/*Demo.java</exclude> -->
<include>**/*RunnerMMT.java</include>
</includes>
</configuration>
</plugin>
TestRunner.class file
plugin = {
"com.vimalselvam.cucumber.ExtentCucumberFormatter:output/report.html"
//"pretty","html:target/cucumber-
htmlreport/cucumber-pretty",
//"json:target/cucumber-report/cucumber.json",
}
@AfterClass
public static void reportSetup()
{
Reporter.loadXMLConfig(new
File("D:\\ProjectsLive_Java\\Pls\\src\\test\\Resources\\extent-
config.xml"));
/*Properties p = System.getProperties();
p.list(System.out);*/
Reporter.setSystemInfo("User
Name",System.getProperty("user.name"));
Reporter.setSystemInfo("Time Zone",
System.getProperty("user.timezone"));
Reporter.setSystemInfo("64 Bit", "Windows 10");
Reporter.setSystemInfo("2.53.0", "Selenium");
Reporter.setSystemInfo("3.3.9", "Maven");
Reporter.setSystemInfo("1.8.0_66", "Java Version");
Reporter.setTestRunnerOutput("Cucumber JUnit Test Runner");
}
extend-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
<configuration>
<!-- report theme -->
<!-- standard, dark -->
<theme>standard</theme>
<!-- document encoding -->
<!-- defaults to UTF-8 -->
<encoding>UTF-8</encoding>
<!-- protocol for script and stylesheets -->
<!-- defaults to https -->
<protocol>https</protocol>
<!-- title of the document -->
<documentTitle>ExtentReports</documentTitle>
<!-- report name - displayed at top-nav -->
<reportName>JUnit TestRunner : Cucumber Report</reportName>
<!-- report headline - displayed at top-nav, after reportHeadline -->
<reportHeadline></reportHeadline>
<!-- global date format override -->
<!-- defaults to yyyy-MM-dd -->
<dateFormat>yyyy-MM-dd</dateFormat>
<!-- global time format override -->
<!-- defaults to HH:mm:ss -->
<timeFormat>HH:mm:ss</timeFormat>
<!-- custom javascript -->
<scripts>
<![CDATA[
$(document).ready(function() {
});
]]>
</scripts>
<!-- custom styles -->
<styles>
<![CDATA[
]]>
</styles>
</configuration>
</extentreports>
答案 0 :(得分:0)
我可以看到您已评论了生成扩展报告的插件,并期望它能够生成报告。因此,我的朋友请撤销对此评论或进行如下更改。 您的测试运行器Java文件应编写如下内容,以启用范围报告。
import com.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import managers.FileReader;
import org.junit.AfterClass;
import org.junit.runner.RunWith;
import java.io.File;
@RunWith(Cucumber.class)
@CucumberOptions(
features = ".//src//test//java//FeatureList",glue = "stepDefinations",
plugin = { "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/STAGE_21081018.html", // this generate the extend report
"junit:target/cucumber-results.xml"}, // this generates the jnuit xml report.
tags="@smoke",
monochrome = true
)
public class TestRunner {
@AfterClass
public static void writeExtentReport() {
Reporter.loadXMLConfig(new File(FileReader.getInstance().getConfigReader().getReportConfigPath())); //extent-config.xml file path
Reporter.setSystemInfo("User Name", System.getProperty("user.name"));
Reporter.setSystemInfo("Time Zone", System.getProperty("user.timezone"));
}
}
希望有帮助。
更新-
添加了我的依赖性-
dependencies {
testCompile 'junit:junit:4.12'
compile group: 'org.seleniumhq.selenium', name: 'selenium-server', version: '2.53.1'
compileOnly 'info.cukes:cucumber-jvm-deps:1.0.5'
compile group: 'org.testng', name: 'testng', version: '6.10'
compile 'com.aventstack:extentreports:3.1.2'
compile group: 'info.cukes', name: 'gherkin', version: '2.12.2'
compile group: 'net.masterthought', name: 'cucumber-reporting', version: '3.18.0'
testCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5'
testCompile group: 'info.cukes', name: 'cucumber-picocontainer', version: '1.2.4'
compile group: 'info.cukes', name: 'cucumber-java', version: '1.2.4'
compile 'com.vimalselvam:cucumber-extentsreport:3.0.2'
compile 'com.aventstack:extentreports:3.1.2'
compile 'org.seleniumhq.selenium:selenium-remote-driver:2.44.0'
}