TestNG Extents Report

A custom testng html report generated by ExtentsReport

License

License

Categories

Categories

TestNG Unit Testing
GroupId

GroupId

com.vimalselvam
ArtifactId

ArtifactId

testng-extentsreport
Last Version

Last Version

1.3.1
Release Date

Release Date

Type

Type

jar
Description

Description

TestNG Extents Report
A custom testng html report generated by ExtentsReport
Project URL

Project URL

http://vimalselvam.com
Source Code Management

Source Code Management

https://github.com/email2vimalraj/TestNGExtentsReport

Download testng-extentsreport

How to add to project

<!-- https://jarcasting.com/artifacts/com.vimalselvam/testng-extentsreport/ -->
<dependency>
    <groupId>com.vimalselvam</groupId>
    <artifactId>testng-extentsreport</artifactId>
    <version>1.3.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.vimalselvam/testng-extentsreport/
implementation 'com.vimalselvam:testng-extentsreport:1.3.1'
// https://jarcasting.com/artifacts/com.vimalselvam/testng-extentsreport/
implementation ("com.vimalselvam:testng-extentsreport:1.3.1")
'com.vimalselvam:testng-extentsreport:jar:1.3.1'
<dependency org="com.vimalselvam" name="testng-extentsreport" rev="1.3.1">
  <artifact name="testng-extentsreport" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.vimalselvam', module='testng-extentsreport', version='1.3.1')
)
libraryDependencies += "com.vimalselvam" % "testng-extentsreport" % "1.3.1"
[com.vimalselvam/testng-extentsreport "1.3.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.testng : testng jar 6.10
com.google.guava : guava jar 20.0

provided (1)

Group / Artifact Type Version
com.aventstack : extentreports jar 3.0.2

Project Modules

There are no modules declared in this project.

TestNG Extents Report

The TestNG Extents report is a listener plugin which you can add it as a listener to your testng suite to generate a nice Extent report.

This listener uses the ExtentReports v3.0.0, a library developed by Anshoo Arora for reporting.

Build Status

Build Status

Why another library?

You don't have to spend time in re-inventing on how to define what. Just add this as a listener or service loader. You will get the nice looking report generated at the end of your test execution.

Also, you will get the emailable report out-of-the box.

Pre-requisite

  • JDK 8+
  • Extent Report v3.0.2+

Usage

For maven, add the following as dependency:

<dependency>
    <groupId>com.vimalselvam</groupId>
    <artifactId>testng-extentsreport</artifactId>
    <version>1.3.1</version>
</dependency>

Either in your testng.xml, add the listener:

<listeners>
    <listener class-name="com.vimalselvam.testng.listener.ExtentTestNgFormatter" />
</listeners>

or add as a service loader (recommended).

By default, the report will be generated at TestNG's output directory. i.e., test-output/report.html and the emailable report at test-output/emailable-report.html.

In case you want to generate the report in a different location, make sure you pass the JVM argument called reportPath with the absolute directory path.

For example: I run my maven test as: mvn clean test -DreportPath=output. This will generate both the reports in the ${project directory}/output.

Adding custom reporter config

You can customize the report using a XML file. The XML file should follow as given here: ExtentReports Configuration.

The XML file should be referred as parameter in your suite xml. The parameter name should be report.config. For instance, the parameter in the suite xml should be as follows:

<parameter name="report.config" value="src/test/resources/extent-config.xml" />

The value should be the config XML file path.

Adding System Information

In case you want to add system information, you will have to implement an interface com.vimalselvam.testng.SystemInfo. This interface contains a method with return type as Map<String, String>. Construct your system information with the map and return that map. After you have implemented, the custom implementation should be referred in your TestNG Suite xml as a parameter at the suite level.

For instance add the following parameter at your suite level in the TestNG suite xml:

<parameter name="system.info" value="test.MySystemInfo" />

The parameter name should be system.info and the value should be your fully qualified custom implementation class name. For example my custom implementation look like this:

package test;

import com.vimalselvam.testng.SystemInfo;
import org.testng.collections.Maps;

import java.util.Map;

/**
 * This is a small utility class to prepare the system information
 */
public class MySystemInfo implements SystemInfo {
    @Override
    public Map<String, String> getSystemInfo() {
        Map<String, String> systemInfo = Maps.newHashMap();
        systemInfo.put("Test Env", "QA");
        systemInfo.put("Browser", "firefox");
        return systemInfo;
    }
}

Instance of the Listener

At any point in time, you can get the instance of the listener as ExtentTestNgFormatter.getInstance()

Adding Screenshot

To add the screenshot, you have two options.

  • If the screenshot can be added from the test method, then
ExtentTestNgFormatter.getInstance().addScreenCaptureFromPath(filePath);
  • If the screenshot can be added from the configuration method, then for example:
@AfterMethod
public void afterMethod(ITestResult iTestResult) throws IOException {
    // The ITestResult is a mandatory parameter
    ExtentTestNgFormatter.getInstance().addScreenCaptureFromPath(iTestResult, filePath);
}

Adding info log

If any case, you want to attach the info log on your test method, you simply call TestNg's Reporter.log method which will be added to your test log. For example:

@Test
public void testMethod() {
    Reporter.log("Custom log");
}

Adding test runner output

To add the test runner output, simply call from anywhere:

ExtentTestNgFormatter.getInstance().setTestRunnerOutput("My output");

Adding new node

Sometimes you may have to add new node under your test. This situation arises when you have iteration in the test method and considering each iteration as a separate node in the report. This could be solved by using addNewNodeToTest() method.

Refer DemoTestClass on how to add new nodes and in case of failure, how to fail the added node.

Cucumber?

Refer my another library which generates the same report for the cucumber based BDD tests: CucumberExtentReporter

Versions

Version
1.3.1
1.3.0
1.2.0
1.1.0
1.0.0