All IT Courses 50% Off
Selenium Tutorials

XSLT Report in Selenium Webdriver

What is XSLT Report?

The XSLT (XML Stylesheet Language for transformation) Report is a language that transforms one XML document into an XHTML document which is suitable for any browser for test reporting display. It is a very important feature in Selenium Framework which is used to develop the reporting system provided by TestNG. It generates the TestNG reports in a user-friendly way and the UI has more user-friendly.

What is XSLT in Selenium?

In Selenium XSLT is a language which transforms one XML document into XHTML document. Using XSLT in XML files we can customize output files by adding and removing attributes that help in interpreting the results fast and is suitable for any browser for test reporting display.

The most commonly used XSL element in the programming:

  • <xsl:if>: This element will place a conditional test against the content of the XML file.
  • <xsl:template>: This element is used to form templates.
  • <xsl:stylesheet> It is an outermost element of a stylesheet. It defines the root element of the style sheet. It tells you that this document is an XSLT style sheet document.
  • <xsl:choose>: It tests against the content of nodes used in conjunction with <xsl: otherwise > and <xsl:when > to specify multiple conditions
  • <xsl:apply-templates> is used to apply template rule to the elements or the current element’s child nodes.
  •  <xsl:value-of>: This element is used to extract the selected node value.
  • <xsl:for-each> This element is used to select every XML element of a specified node-set.
  • <xsl:sort> is used to sort the output.

Required Pre-requisite to generate XSLT reports

  1. ANT build tool is needed to be installed to configure your project with the ANT build tool
  2. XSLT Package downloaded inside the project folder
  3. The Selenium project must be executed with TestNG

ANT set up in the Selenium project

Below are the steps to set up ANT in your Selenium project. ANT is a Java build tool that is written in XML which is mainly used to compile the code.

STEP 1: DOWNLOAD THE ANT ZIP FILE

Go to the URL http://ant.apache.org/bindownload.cgi and download it from the current release version.

XSLT Report in Selenium Webdriver

STEP 2: EXTRACT AND THE ANT FILE SET UP

Extract the zip file and set up its path.

Right-click on My Computer>Click Properties>click on Advanced system settings> Click on Environment Variables.

XSLT Report in Selenium Webdriver

STEP 3: ENVIRONMENT VARIABLE SET UP

Click on Environment Variables to set up the environment variable. Click on the New button and enter the Variable name and Variable value as the path of Ant folder till bin.

XSLT Report in Selenium Webdriver
XSLT Report in Selenium Webdriver

STEP 4: SYSTEM VARIABLE SET UP

Now set up the System variable. Click on New and add the bin path.

XSLT Report in Selenium Webdriver

STEP 5: VALIDATE BUILD ON CMD

Open CMD prompt and type command- ant.

Generate XSLT Report in Selenium

In this scenario, we will use the Facebook site to generate the XSLT report in Selenium.

Scenario: In the following scenario you will automate and generate XSLT report 

Launch the web browser

By using the below steps we will generate an XSLT report in selenium Webdriver 

Step 1: Create and execute the Selenium script for the Facebook site.

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class SeleniumTest {

        public static void main(String[] args) {
            System.setProperty("webdriver.chrome.driver", "F:\\drivers\\chromedriver.exe");
            //create chrome instance
            driver = new ChromeDriver();
            driver.get("http://www.facebook.com/");
            WebElement element = driver.findElement(By.xpath("//input[@name='email']"));
            element.sendKeys("xxxx@gmail.com");
            WebElement element = driver.findElement(By.xpath("//input[@name='pass']"));
            element.sendKeys("xxxx");
            WebElement button = driver.findElement(By.xpath("//input[@name='login']"));
            button.click();
        }
    }

Step 2: To download the XSLT report package go to the https://drive.google.com/drive/folders/1nic2hXP6JYSEMJ-JXS4JBk4MU3VfUiX1

XSLT Report in Selenium Webdriver

Unzip the above-extracted XSLT Report folder you will find the below items:

  • build.xml
  • testng-results.xsl
XSLT Report in Selenium Webdriver

STEP 3: STORE THE FILE IN YOUR PROJECT

Go to the directory of your project then inside your project folder store the extracted XSLT file.

XSLT Report in Selenium Webdriver

In Eclipse when you refresh your project folder you will see the XSLT files are added in the project.

XSLT Report in Selenium Webdriver

GENERATION OF ‘TESTNG-XSLT’ FOLDER IN THE PROJECT DIRECTORY

In eclipse go to your project and right-click on build.xml and Run as Ant Build.

XSLT Report in Selenium Webdriver

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

XSLT Report in Selenium Webdriver

Click on the Run button and it will generate the report.

You will see the testng-xslt folder added to your project directory.

XSLT Report in Selenium Webdriver

Open this folder and click on the index.html file to see the report in your browser.

XSLT Report in Selenium Webdriver

Run the index file and you will find the report which represents the test status more clearly.

XSLT Report in Selenium Webdriver

Conclusion:

  • It generates the TestNG reports in a user-friendly way and the UI has more user-friendly.
  • It stands for Extensible Stylesheet Language Transformations.
  • The XSLT (XML Stylesheet Language for transformation) Report is a language that transforms one XML document into an XHTML document which is suitable for any browser for test reporting display.
  • It is a very important feature in Selenium Framework which is used to develop the reporting system provided by TestNG.
Selenium Training with Live Project
Facebook Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button
Close
Close

Get Selenium Training Online
Course Now at 50%OFF!

Offer valid for 1st 20 seats only, Hurry up!!

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

H2kinfosys will use this information to be in touch with you for providing updates.