info@pragmatictesters.com +94 11 253 8512

Introduction

Test reporting is one of the important aspect in any test automation process. Test reports should be generated automatically at the end of test execution.

ReportNG can be used for generating test reports in HTML and XML formats in Selenium WebDriver (Java) projects. 

In this post you will see integrating your existing Selenium WebDriver + TestNG test suite with ReportNG inside IntelliJ IDEA IDE.

It is assumed that you are already familiar with the Selenium WebDriver integration with TestNG.

You can customise the test reports by  customising the stylesheets.

Steps

Prerequisites: A sample (Selenium + TestNG + Maven) project with tests is  available. Test suite file testng.xml is created and tests are added to the test suite (testing.xml).

We assume that you are already familiar with the Selenium WebDriver basic scripting with TestNG and Maven .

Steps involved in integrating ReportNG

  1. Add ReportNG and Guice dependencies to  POM.xml  
  2. Add surefire plugin to POM.xml 
  3. Add listeners to testNG.xml 
  4. Configure test suite (testNG.xml).
  5. Run the test suite 
  6. View the reports 

Adding Dependencies to pom.xml 

You should have selenium-java and testng dependencies already added into pom.xml. Add reportng and guice dependencies to pom.xml. Your pom.xml will look like following after adding the two additional dependencies. 

<dependencies>

<dependency> 
          <groupId>org.seleniumhq.selenium</groupId> 
          <artifactId>selenium-java</artifactId>
          <version>3.141.59</version> 
</dependency>

<dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>6.14.3</version>
 </dependency>


<dependency>
         <groupId>org.uncommons</groupId>
         <artifactId>reportng</artifactId>
         <version>1.1.4</version>
</dependency>

<dependency>
         <groupId>com.google.inject</groupId>
         <artifactId>guice</artifactId>
         <version>4.2.2</version>
</dependency>
</dependencies>

Please replace the versions with the latest compatible versions

Adding maven-surefire-plugin to the pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <properties> <property>
                        <name>usedefaultlisteners</name>
                        <value>false</value> 
                     </property>
                    <property>
                        <name>listener</name>
                        <value>org.uncommons.reportng.HTMLReporter,  
                                   org.uncommons.reportng.JUnitXMLReporter
                        </value> 
                  </property> </properties>
            </configuration>
        </plugin>
    </plugins>
</build>

Above should be added after the </dependencies> tag and before the </project> tag in your pom.xml 

Adding listeners

Add following listeners to the TestNG.xml.

<listeners>
        	<listener class-name="org.uncommons.reportng.HTMLReporter"/>
       	<listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>
</listeners>

Sample pom.xml and testing.xml files

Configure testng.xml

Next you need to make testing.xml file runnable if run option is not available from context menu of testing.xml file.

  • Click on Run→ Edit Configuration menu in IntelliJ IDEA

  • Click on + sign in the left top corner
  • Select TestNG from the list

  • Type a Name
  • Select Test kind :  as Suite from the list
  • Select the testng.xml test suite file into Suite: field 
  • Select (or create) a target folder to output the reports

  • Click Apply and OK buttons to save the new configuration.

Run the test suite

  • Click run→ Run <Testsuite-name> menu item in IntelliJ IDEA

Also you should be able to run the testing.xml from the context menu too.

Wait till the tests are executed

Checking the test reports

Generated reports will be in the target folder. You can open the report file from IntelliJ IDEA.

  • Navigate to the report output –> html folder 
  • Select index.html file
  • Right click on the index.html file
  • Select Open in Browser –> <Web browser>

Sample Report

Following is a sample (default) report generated by ReportNG. The report layout and content can be customized by updating the style sheets. 

Refernce

Dyer, D.  ReportNG – An HTML/XML reporting plug-in for TestNG. [online] Reportng.uncommons.org.
Available at: https://reportng.uncommons.org/
[Accessed 07 March 2020].

sams, P. ReportNG – HTML/XML Reporting Plug-in for TestNG. [online] Seleniumworks.blogspot.com.
Available at: http://seleniumworks.blogspot.com/2013/01/reportng-htmlxml-reporting-plug-in-for.html
[Accessed 07 March 2020.

Author: Janesh Kodikara

Performance Tester | JMeter Trainer | Software Testing Service Provider

Your Turn To Talk

Leave a reply:

Your email address will not be published.