Reports generation in TestNG

The test report is the most important feature of the Selenium framework.

Different types of report generation:

  1. Default report of testNG
    -We already checked this before and it exists in test-output folder.

  2. Extent Report

  3. XSLT Report



Pre-requisites to Generate Extent Reports:

  1. Java should be installed (Link to Install and setup Java)

  2. TestNG should be installed (Not Mandatory)

  3. Extent Report Jars (Version 2.41.2) should be installed –
    Open link http://www.javabykiran.com/selenium/downloads/extentreports/

  4. extent-config.xml – It allows us to configure HTML Report. (Not Mandatory)
    Open link http://www.javabykiran.com/selenium/downloads/extentreports/


Steps To Generate Extent Reports:

  1. First create a TestNG project in eclipse

  2. Now download extent library files from the following link: http://www.javabykiran.com/selenium/downloads/extentreports/

  3. Add the downloaded library files in your project

  4. Create a java class say ‘ExtentReportsExample’ and add following code in it

ExtentReportsExample.java


extent-config.xml:

By using this external XML file (extent-config.xml), we could change the details such as Report Theme (either standard or dark), Report Title, Document Title etc.,
We use extent object and use loadConfig () method to load this xml file.

Now run this above program but before running we need to check directory structure. All jars must be in build path.

testng report example

Now refresh project and go to “test-output” folder. You will see the screen as shown in the below file.

extent reports jar file

Open report and it will show the below screen.

extent report in testng

In Selenium, TestNG provides its default reporting system. To enhance the reporting feature further XSLT Report proves helpful. It also has more user-friendly UI and detail description for the test suite result.

What is XSLT?

  • XSLT stands for “Extensible Stylesheet Language Transformations”. XSLT is a language for transforming XML documents into other XML documents (XHTML) that are used by a browser.

  • With XSLT, we can customize the output file by adding/removing attributes and elements in the XML file. This helps us to interpret the result quickly. All browsers support XSLT. It uses XPath to navigate through elements and attributes in XML documents.

  • Below are the most popularly used XSL element in programming:

      < xsl:stylesheet>: It defines that the document is an XSLT style sheet document.
      < xsl:if>: It is used to put a conditional test against the content of the XML file.
      < xsl:template>: It is used to build templates.
      < xsl:apply-templates>: It is used to apply templates to elements.
      < xsl:choose>: It is used in conjunction with < xsl: otherwise> and < xsl:when> to express multiple conditions.
      < xsl:for-each>: It is used to select every XML element of a specified node.
      < xsl:value-of>: It is used to extract the value of a selected node.
      < xsl:sort>: It is used to sort the output.

  • Pre-requisite to generate XSLT report. Following is the pre-requisite to generate XSLT report:

    1. ANT build tool should be installed (Its necessary to install ANT for XSLT reporting feature). ANT is used to compile the source code and create the build. It is also very much extensible.

    2. XSLT package downloaded.

    3. Selenium script should be executed by TestNG.

What is Ant?

  • Apache Ant is a Java based build tool from Apache.

  • Apache Ant’s build files are written in XML.

  • Open Source tool.

Steps To Install ANT-

  • Step 1- Download ant zip file.

  • Step 2- Extract Zip file and then we need to set environment variable by following below steps.

  • Step 3- Right click on My computer and select the properties and click on Advanced system setting.

apache ant intallation

apache ant intallation


Scenario: We will automate and generate XSLT report for the below scenario:

Step 1- Create 2 Test case as below:


Step 2- Download the XSLT report packagexslt report package

Step 3- Unzip the folder and copy all files and paste at the project home directory as shown in below screen.xslt report package

Step 4- Refresh your project in eclipse and you will able to see build.xml filebuild.xml file in testng folder

  • Now Run first your testcases with TestNG and then Run this build.xml file

  • Right click on build.xml and Run as Ant build

  • Then a new window opens. Now select option ‘generateReport’.

generate xslt report in testng

Click on Run button. It should generate the report.

Once build is successful and moved to project home directory. We will find the testng-xslt folder.

testng xslt report

Open the folder and check Index.html file. You will see below report:

index.html file in xslt report

verify xslt report in testng