Skip to content
This repository has been archived by the owner on Jan 15, 2023. It is now read-only.

Commit

Permalink
Added feature to configure the report location in 3 different ways
Browse files Browse the repository at this point in the history
  • Loading branch information
email2vimalraj committed Jun 12, 2017
1 parent 7127ad2 commit 68d2424
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
19 changes: 17 additions & 2 deletions src/main/java/com/cucumber/listener/ExtentCucumberFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
public class ExtentCucumberFormatter implements Reporter, Formatter {

public static final String REPORT_PATH_PROPERTY = "cucumberReportPath";
private static ExtentReports extentReports;
private static ExtentHtmlReporter htmlReporter;
private static ThreadLocal<ExtentTest> featureTestThreadLocal = new InheritableThreadLocal<>();
Expand All @@ -40,8 +41,22 @@ private static void setExtentHtmlReport(File file) {
if (htmlReporter != null) {
return;
}
if (!file.exists()) {
file.getParentFile().mkdirs();
try {
if (!file.exists()) {
file.getParentFile().mkdirs();
}
} catch (NullPointerException e) {
String filePath;
if (System.getProperty(REPORT_PATH_PROPERTY) != null && !System.getProperty(REPORT_PATH_PROPERTY).isEmpty()) {
filePath = System.getProperty(REPORT_PATH_PROPERTY);
} else {
filePath = "output" + File.separator + "Run_" + System.currentTimeMillis() +
File.separator + "report.html";
}
file = new File(filePath);
if (!file.exists()) {
file.getParentFile().mkdirs();
}
}
htmlReporter = new ExtentHtmlReporter(file);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/cucumber/runner/MyTestNGCukesRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
public class MyTestNGCukesRunner extends AbstractTestNGCucumberTests {
@AfterClass
public static void setup() {
public static void teardown() {
Reporter.loadXMLConfig(new File("src/test/resources/extent-config.xml"));
Reporter.setSystemInfo("user", System.getProperty("user.name"));
Reporter.setSystemInfo("os", "Mac OSX");
Expand Down
9 changes: 7 additions & 2 deletions src/test/java/com/cucumber/runner/RunCukesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;

import java.io.File;
Expand All @@ -15,12 +16,16 @@
@CucumberOptions(
features = {"src/test/resources/features"},
glue = {"com.cucumber.stepdefinitions"},
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:output/report.html"}
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:"}
)
public class RunCukesTest {
@BeforeClass
public static void setup() {
System.setProperty("cucumberReportPath", "output/myreport.html");
}

@AfterClass
public static void setup() {
public static void teardown() {
Reporter.loadXMLConfig(new File("src/test/resources/extent-config.xml"));
Reporter.setSystemInfo("user", System.getProperty("user.name"));
Reporter.setSystemInfo("os", "Mac OSX");
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/com/cucumber/runner/TestNGCukesRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;

import java.io.File;

@CucumberOptions(
features = {"src/test/resources/features/MyFeature.feature"},
glue = {"com.cucumber.stepdefinitions"},
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:output/report.html"}
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:"}
)
public class TestNGCukesRunner extends AbstractTestNGCucumberTests {
@BeforeClass
public static void setup() {
System.err.println("Hello");
}

@AfterClass
public static void setup() {
public static void teardown() {
Reporter.loadXMLConfig(new File("src/test/resources/extent-config.xml"));
Reporter.setSystemInfo("user", System.getProperty("user.name"));
Reporter.setSystemInfo("os", "Mac OSX");
Expand Down

0 comments on commit 68d2424

Please sign in to comment.