Selenium
How to Read/Write Data from Excel File: Selenium POI
File IO is a critical part of any software process. We frequently create a file, open it & update...
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.
In this XSLT tutorial, you will learn –
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:
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.
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
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:
Unzip the above folder you will get below items:
Step 3): Unzip the folder and copy all files and paste at the project home directory as shown in below screen.
Step 4): In this step run the build.xml file from eclipse as shown below:
Right click on the build.xml then click on run as Ant build.
Then a new window opens. Now select option 'generateReport'.
Click on Run button. It should generate the report.
Once build is successful and moved to project home directory. You will find the testng-xslt folder.
Inside this folder you will find index.html file as shown below:
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.
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:
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.
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" ); }
@Test(priority=3) public void Logout() { throw new SkipException("Skip this"); }
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:
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.
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.
XSLT report is required to enhance the TestNG reporting feature in a very user-friendly way.
File IO is a critical part of any software process. We frequently create a file, open it & update...
The following Java Selenium interview questions guide covers 100 most important interview...
In this tutorial, we will learn, Store commands, Echo commands, Alerts and Popup handling. Storing...
What is JavaScriptExecutor? JavaScriptExecutor is an Interface that helps to execute JavaScript...
What is Ajax? AJAX stands for Asynchronous JavaScript & XML, and it allows the Web page to...
What is a Proxy? A proxy acts as an intermediary between clients sending requests and server...