Extension to Extent Report 3

maxresdefault

         This article is an extension of Extent Report TestNG which helps you to use the latest Extent report library 4 series introduced by aventstack. This is the time to migrate version 3 to 4. Here I would like to share the basic changes in version 4. The first thing is ExtentHtmlReporter class deprecated and introduced ExtentSparkReporter.

      ExtentSparkReporter is the default version 4 reporter supporting both BDD and non-BDD test styles. The ExtentSparkReporter creates a rich standalone spark file. It allows several configuration options via the config() method. In the new version, no need to load the extent-config.xml via code. The library itself configure the default style for the HTML report but we have to specify the directory path to store HTML report before start the test suite. We can also specify the themes for the HTML report, it supports DARK and STANDARD themes.

   As usual, the object of ExtentReports class helps to attach the object of ExtentSparkReporter and also to set system information in the HTML file, map each test into the HTML report. Finally, we have to flush the object o ExtentReports class. The object of ExtentTest class helps to keep track of the status of each test case into the HTML report with assign specific color for the test.

Prerequisites to Generate Extent Reports:

  1. Java should be installed and setup Java
  2. TestNG maven dependency should be available
  3. Extent Report Maven dependency should be available

<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>4.1.3</version>
</dependency>

Below is the code snippet for before suite,

public static ExtentSparkReporter sparkReporter;
public static ExtentReports extentReport;
String reportPath = System.getProperty(“user.dir”) + “/AutomationReport/”;

sparkReporter = new ExtentSparkReporter(reportPath);
sparkReporter.config().setDocumentTitle(“Appium Automation”);
sparkReporter.config().setReportName(“Automation Execution Report”);
sparkReporter.config().setTheme(com.aventstack.extentreports.reporter.configuration.Theme.DARK);
extentReport = new ExtentReports();
extentReport.attachReporter(sparkReporter);
extentReport.setSystemInfo(“Application Name”, “ExtentReport”);
extentReport.setSystemInfo(“Platform”, System.getProperty(“os.name”));
extentReport.setSystemInfo(“Environment”, “QA”);

     Below is the code snippet to collect the test method name prior to each test execution. This logic you can add before method section,

String className = this.getClass().getSimpleName();
extentTest = extentReport.createTest(className + “-” + method.getName()); //method object of Method class should be passed to get the method name.

     Below is the code snippet to collect the test results after each test execution and map those results into the HTML report. You can use the below logic after method section,

public static ExtentTest extentTest;

String methodName = result.getName();
extentTest.createNode(methodName);
if (result.getStatus() == ITestResult.FAILURE) {
extentTest.log(Status.FAIL, MarkupHelper.createLabel(methodName + ” – Test Case Failed”, ExtentColor.RED));
extentTest.log(Status.FAIL,
MarkupHelper.createLabel(result.getThrowable() + ” – Test Case Failed”, ExtentColor.RED));
// Here you can add screenshot in the report for fail case
extentTest.fail(methodName + “Test Step Failed”);
}
if (result.getStatus() == ITestResult.SKIP) {
extentTest.log(Status.SKIP,
MarkupHelper.createLabel(result.getName() + ” – Test Case Skipped”, ExtentColor.ORANGE));
extentTest.skip(methodName + “Test Step Skipped”);
}
if (result.getStatus() == ITestResult.SUCCESS) {
extentTest.log(Status.PASS,
MarkupHelper.createLabel(result.getName() + ” Test Case PASSED”, ExtentColor.GREEN));
extentTest.pass(methodName + “Test Step Passed”);
}

     The below final code snippet helps to flush the object of the ExtentReports class and also rename the generated file name with time-stamp. By default, the library will generate index.html file. After suite, we can rename the HTML report along with flushing the object of the ExtentReports class.

extentReport.flush();
DateFormat dateFormat = new SimpleDateFormat(“dd-MMM-yyyy_HH-mm-ss”);
Date date = new Date();
String filePathdate = dateFormat.format(date).toString();
String actualReportPath = reportPath + “index.html”;
new File(actualReportPath).renameTo(new File(
System.getProperty(“user.dir”) + “/AutomationReport/” + “Automation_” + filePathdate + “.html”));

Below are the sample screenshots of the generated HTML report.

Report2

Report3

Report1

Try to migrate your extent report 3 versions to 4 series and enjoy the differences.

make it perfect!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s