XSLT Report in Selenium Webdriver

XSLT Report

The XSLT Report in the Selenium framework is a very important feature that is used to further enhance the default reporting system provided by Testng. It enhances the Testng reporting feature in a very user-friendly way. It also has more user-friendly UI and detailed description for the test suite results.

What is XSLT in Selenium?

XSLT in Selenium is language for transforming XML documents into other XML documents. We can customize output files by adding/removing attributes and elements in XML files using XSLT. This helps interpreting results quickly and it is supported by all browsers. It uses XPath to navigate through elements and attributes in XML documents. XSLT stands for Extensible Stylesheet Language Transformations.

Below are the most popularly used XSL element in programming:

  • <xsl:stylesheet> It defines that this document is an XSLT style sheet document.
  • <xsl:if> is used to put a conditional test against the content of the XML file.
  • <xsl:template> is used to build templates.
  • <xsl:apply-templates> is used to apply templates to elements.
  • <xsl:choose> is used in conjunction with <xsl: otherwise > and <xsl:when > to express multiple conditions.
  • <xsl:for-each> is used to select every XML element of a specified node.
  • <xsl:value-of> is used to extract the value of a selected node.
  • <xsl:sort> 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 install (Its necessary to install ANT for XSLT reporting feature). ANT is used to compile the source code and creating the build. It is also very much extensible. Refer this link for steps to download and install ANT.

2) XSLT package downloaded.

3) Selenium script that should be executed by TestNG.

We will discuss XSLT report in Selenium Webdriver during this example.

Generate XSLT Report in Selenium

In this scenario, we will use Guru99 demo site to illustrate Generate XSLT report.

Scenario: You will automate and generate XSLT report for the following scenario

  • Launch the web browser
  • Launch the Firefox and open the site http://demo.guru99.com/V4/

Generate XSLT Report in Selenium

  • Login to the application.

Generate XSLT Report in Selenium

  • Log out from the application.

    Generate XSLT Report in Selenium

Now we will generate XSLT report in selenium as given in below steps.

Step 1) For the above-mentioned scenario. Create and execute the Selenium script for Guru99 demo site.

import org.openqa.selenium.Alert;		
import org.openqa.selenium.By;		
import org.openqa.selenium.WebDriver;		
import org.openqa.selenium.firefox.FirefoxDriver;		
import org.testng.Assert;		
import org.testng.annotations.Test;		
    		
public class Testing {				
    WebDriver driver= new FirefoxDriver();					

    @Test(priority=1)			
    public void Login() 					
    {		
        //Launching the Site.		
        driver.get("http://demo.guru99.com/V4/");					
                        		
        //Login to Guru99 		
        driver.findElement(By.name("uid")).sendKeys("mngr34926");							
        driver.findElement(By.name("password")).sendKeys("amUpenu");							
        driver.findElement(By.name("btnLogin")).click();					
        //Verifying the manager home page		
        Assert.assertEquals(driver.getTitle(),"Guru99 Bank Manager HomePage" );					
    }		
    		
    @Test(priority=2)			
    public void verifytitle()					
    {		
        //Verifying the title of the home page		
        Assert.assertEquals(driver.getTitle(),"Guru99 Bank Manager HomePage" );					
        }		
    		
    @Test(priority=3)			
    public void Logout()					
    {		
        driver.findElement(By.linkText("Log out")).click();					
        Alert alert=driver.switchTo().alert();			
        alert.accept();		
        //Verifying the title of the logout page		
        Assert.assertEquals(driver.getTitle(),"Guru99 Bank Home Page" );					
    }		
}	

Step 2) Download the XSLT report package from this link:

Generate XSLT Report in Selenium

Unzip the above folder you will get below items:

  • build.xml
  • testng-results.xsl

Generate XSLT Report in Selenium

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

Generate XSLT Report in Selenium

Step 4) In this step run the build.xml file from eclipse as shown below:

Generate XSLT Report in Selenium

Right click on the build.xml then click on run as Ant build.

Generate XSLT Report in Selenium

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

Generate XSLT Report in Selenium

Click on Run button. It should generate the report.

Verifying XSLT Report

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

Verifying XSLT Report

Inside this folder you will find index.html file as shown below:

Verifying XSLT Report

Now open this HTML file in any browser like Firefox or Chrome, which support javascript. You will find the report as shown in below screen. The pie chart report represents test status more clearly. The filter feature allows the user to filter the result as per the set criteria.

Verifying XSLT Report

You will find the pie chart showing the percentage of passed, failed and skipped test.

To display the result in regular format click on the Default suite from the left-hand side of the pane. It should show the details of each test as shown in below screen:

Verifying XSLT Report

Now we forcefully make a test pass, fail and skip.

To view a report of each type for the test result, we need to do some changes in below methods.

  1. verifytitle() : In the Assert, we pass the wrong expected page title. When the code is executed, it does not match the expected title. Hence making the test fail.
  2. Logout() : In this method, we forcefully skip the test by using skipexception. So that when the code is executed, this method will get skip.

By doing so, we are trying to show XSLT report with the help of pie chart. It will show the test result for a pass, fail and skip test.

@Test(priority=2)		
    public void verifytitle()					
    {		
    	//Verifying the title of the home page		
    	Assert.assertEquals(driver.getTitle(),"Guru99 Bank Manager" );					
    }

Verifying XSLT Report

@Test(priority=3)		
    public void Logout()					
    {		
        throw new SkipException("Skip this");			
        		
    }

Verifying XSLT Report

Now we have one test for each type of result status, i.e., pass, fail and skip.

After execution of script and build.xml. Verify the XSLT report as shown in the below screen:

Verifying XSLT Report

The test report is more user-friendly report and easy to understand. You can also filter the result by selecting the check box in the below screen.

Verifying XSLT Report

Note: In the screenshot the ‘config’ option display the test for which the configuration is done. In big project, there are lots of configuration code. So usually it is used in big projects.

Summary

XSLT report is required to enhance the TestNG reporting feature in a very user-friendly way.

  • XSLT stands for Extensible Stylesheet Language Transformations.
  • Download and installation of ANT build refer to given link.
  • Generated the XSLT report in selenium and executed the build.xml from eclipse.
  • Verify the XSLT report from project folder.
  • Verify the XSLT report of each type of result status.