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
- ANT build tool is needed to be installed to configure your project with the ANT build tool
- XSLT Package downloaded inside the project folder
- 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.
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.
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.
STEP 4: SYSTEM VARIABLE SET UP
Now set up the System variable. Click on New and add the bin path.
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
- Open the Firefox browser and navigate to the “http://www.facebook.com”
- Login to the application
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("[email protected]");
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
Unzip the above-extracted XSLT Report folder you will find the below items:
- build.xml
- testng-results.xsl
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.
In Eclipse when you refresh your project folder you will see the XSLT files are added in the project.
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.
Then a new window opens. Now select option ‘generateReport’.
Click on the Run button and it will generate the report.
You will see the testng-xslt folder added to your project directory.
Open this folder and click on the index.html file to see the report in your browser.
Run the index file and you will find the report which represents the test status more clearly.
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.