About

ExtentService is used by all plugins (Cucumber, TestNG etc) and provides a way to load desired reporters easily through a properties file or System.setProperty.


Adding Reporters

Reporters can be added using an external properties file or System.setProperty().


Properties

The Extent-TestNG listener looks for the following file in your classpath:

  1. 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 used
  • extent.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.

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:

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
}