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

extentreports-testng-adapter


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 are added to your project and configured via ExtentService, already part of the plugin. See here for details.


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