Getting Started
extentreports-testng-adapter
is the official TestNG plugin which does all the heavy-lifting for you and can output information in multiple levels. Continue reading for more details.
Download
Start using the TestNG listener for Extent Framework by adding the dependency below.
Maven
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports-testng-adapter</artifactId>
<version>${version}</version>
</dependency>
If you are using the professional version and would like to add the extentreports
dependency from systemPath:
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports-testng-adapter</artifactId>
<version>${version}</version>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>${version}</version>
<scope>system</scope>
<systemPath>/usr/extentreports-${version}.jar</systemPath>
</dependency>
If the above does not work, you can exclude the extentreports
dependency from the adapter and explicitly add the depedency from systemPath:
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports-testng-adapter</artifactId>
<version>${version}</version>
<exclusions>
<exclusion>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>${version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>${version}</version>
<scope>system</scope>
<systemPath>/usr/extentreports-${version}.jar</systemPath>
</dependency>
Gradle
dependencies {
compile "com.aventstack:extentreports-testng-adapter:${version}"
}
GitHub
Listeners
As part of the extentreports-testng-adapter
distribution, you get multiple listeners to include with your project, depending upon your reporting requirements.
ExtentITestListenerClassAdapter
(ITestListener)ExtentITestListenerAdapter
(ITestListener)ExtentIReporterSuiteClassListenerAdapter
(IReporter)ExtentIReporterSuiteListenerAdapter
(IReporter)
Each listener in this section can be added to your test or base class:
@Listeners(ExtentITestListenerClassAdapter.class)
public class MyTests {
@Test
public void test() {
...
}
}
or to your suite file:
<suite name="Regression" parallel="none">
<listeners>
<listener class-name="com.aventstack.extentreports.adapter.listener.ExtentITestListenerClassAdapter"></listener>
</listeners>
<test name="MyTest">
<classes>
<class name="package.class" />
</classes>
</test>
</suite>
ITestListener
ExtentITestListenerClassAdapter
As the name suggests, this is a ITestListener
listener, which builds reports at 2 levels:
Class
-
Test
Since this is an implementation of ITestListener
, report will be updated after a test finishes. In other words, this listener will provide an updated view of the report after each test.
ExtentITestListenerAdapter
As the name suggests, this is a ITestListener
listener, which builds reports at 1 level:
Test
Since this is an implementation of ITestListener
, report will be updated after a test finishes. In other words, this listener will provide an updated view of the report after each test.
IReporter
IReporter adapters are triggered when all tests in your suite are finished. Due to this, a report will only be generated after suite completion.
ExtentIReporterSuiteClassListenerAdapter
As the name suggests, this is a IReporter
listener, which builds reports at 3 levels:
Suite
-
Class
Test
Since this is an implementation of IReporter
, report will be generated when all your tests have finished running.
ExtentIReporterSuiteListenerAdapter
As the name suggests, this is a IReporter
listener, which builds reports at 2 levels:
Suite
-
Test
Since this is an implementation of IReporter
, report will be generated when all your tests have finished running.
Adding Reporters
Reporters can be added using an external properties file or System.setProperty("reporter-key", "value")
.
Properties
The Extent-TestNG listener looks for the following file in your classpath:extent.properties
The properties files have 3 core components where ${name}
is the name of the reporter (avent, bdd, logger, email etc.):
extent.reporter.${name}.start
: [true/false] used to indicate the listener whether the reporter will be usedextent.reporter.${name}.config
: [path of the config file] path of the reporter configuration.xml (Note: Klov uses a properties configuration). Reporter's XML configuration can be found in the reporter's docs under Configuration/XML.extent.reporter.${name}.out
: [output path] path where the report will be stored (Note: Klov does not use this key as no files are written to disk)
Initialization Properties
Below are the comprehensive properties to intialize reporters:
#extent.properties
extent.reporter.avent.start=true
extent.reporter.bdd.start=true
extent.reporter.cards.start=true
extent.reporter.email.start=true
extent.reporter.html.start=true
extent.reporter.klov.start=true
extent.reporter.logger.start=true
extent.reporter.tabular.start=true
extent.reporter.avent.config=avent-config.xml
extent.reporter.bdd.config=bdd-config.xml
extent.reporter.cards.config=cards-config.xml
extent.reporter.html.config=html-config.xml
extent.reporter.klov.config=klov.properties
extent.reporter.logger.config=logger-config.xml
extent.reporter.tabular.config=tabular-config.xml
extent.reporter.avent.out=test-output/AventReport/
extent.reporter.bdd.out=test-output/BddReport/
extent.reporter.cards.out=test-output/CardsReport/
extent.reporter.email.out=test-output/EmailReport/ExtentEmail.html
extent.reporter.html.out=test-output/HtmlReport/ExtentHtml.html
extent.reporter.logger.out=test-output/LoggerReport/
extent.reporter.tabular.out=test-output/TabularReport/
If you use only the Avent reporter, your property file would now look like:
#extent.properties
extent.reporter.avent.start=true
extent.reporter.avent.config=avent-config.xml
extent.reporter.avent.out=test-output/AventReport/
If you use Avent with Klov, your property file would now look like:
#extent.properties
extent.reporter.avent.start=true
extent.reporter.avent.config=avent-config.xml
extent.reporter.avent.out=test-output/AventReport/
extent.reporter.klov.start=true
extent.reporter.klov.config=klov.properties
System.setProperty()
It is possible to start reporters, provide configuration and output values through the use of System.setProperty("k", "v");
. The keys as described in Initialization Properties section define the context which can be used with System.setProperty
also.
If you are using System.setProperty()
, make sure extent.properties
is not in your classpath. These properties file are loaded by default causing configuration clashes with the supplied System settings.
@Listeners(ExtentITestListenerClassAdapter.class)
public class SomeTestClass extends SomeBaseClass {
static {
System.setProperty("extent.reporter.avent.start", "true");
System.setProperty("extent.reporter.avent.config", "avent-config.xml");
System.setProperty("extent.reporter.avent.out", "test-output/AventReport/");
System.setProperty("extent.reporter.klov.start", "true");
System.setProperty("extent.reporter.klov.config", "klov.properties");
}
// .. tests
}
or directly in your BaseClass:
@Listeners(ExtentITestListenerClassAdapter.class)
public abstract class SomeBaseClass {
static {
System.setProperty("extent.reporter.avent.start", "true");
System.setProperty("extent.reporter.avent.config", "avent-config.xml");
System.setProperty("extent.reporter.avent.out", "test-output/AventReport/");
System.setProperty("extent.reporter.klov.start", "true");
System.setProperty("extent.reporter.klov.config", "klov.properties");
}
// .. some code
}
Assign Test Attributes
To assign attributes to your tests (tag, author or device), it is required to decorate @Test(groups = {})
.
By default, each test group is assigned as a category or tag. By adding the a:
or author:
qualifiers, the test can be marked with an author. By adding d:
or device:
, the test will be marked with a device.
@Listeners({ExtentITestListenerClassAdapter.class})
public class Tests {
@Test(groups = { "tagName", "t:another-tagName", "a:authorName", "d:deviceName" })
public void test1(String user, String password) {
Assert.assertTrue(true);
}
@Test(groups = { "tagName", "tag:another-tagName", "author:authorName", "device:deviceName" })
public void test2(String user, String password) {
Assert.assertTrue(false);
}
}
test1
and test2
both use the same attributes:
- tagName: will be assigned as a category (
assignCategory()
) - t:another-tagName, tag:another-tagName: will be assigned as a category
- a:authorName, author:authorName: will be assigned as an author
- d:deviceName, device:deviceName: will be assigned as a device
Assign Tag
By default, all groups are assigned as tags. You can also use the below qualifiers to mark the test with the aventstack category:
- t:aventstack
- tag:aventstack
Assign Device
Qualifiers below will assign your test with a sgs
and iphonex
device:
- d:sgs
- device:iphonex
Assign Author
Qualifiers below will assign your test with Anshoo
as the author:
- a:Anshoo
- author:Anshoo
Changelog
Version 4.0.0
Released on September 30, 2018
Initial