Saturday, April 25, 2015

XSLT report in Selenium

 

 

XSLT: XML Stylesheet language transformation

When we execute our project using TestNg.xml, it automatically create a basic html report and testng-results.xml.
XSLT is going to use this testing-result.xml and transform into better htmlreport


Steps to Generate XSLT reports

Step1: Create a project having test cases like

  • Pass
  • Fail
  • Skip
 with TestNG annotations .


Create 4 .java files such a way that: 2 successful, 1 skipped and 1 failed on run

testcase1: pass


package test;

import org.testng.annotations.Test;
import org.testng.annotations.Test;

public class passtc {
   
    @Test
    public void passresult()
    {
        System.out.println("Pass");
    }

}

 

testcase2: pass


package test;

import org.testng.annotations.Test;

public class passtc1 {
   
    @Test
    public void show()
    {
        System.out.println("Testcase2 passed");
    }

}

 

testcase3: failed


package test;

import org.testng.annotations.Test;
import org.testng.AssertJUnit;
import org.testng.Assert;
import org.testng.annotations.Test;

public class failtc {
   
    @Test
    public void failresult()
    {
        System.out.println("Fail");
        AssertJUnit.assertEquals("Fail", "Pass");
    }

}



testcase4: skipped


 package test;

import org.testng.SkipException;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class skiptc {
   
    @BeforeTest
    public void intlize()
    {
        System.out.println("this test will skip");
      
    }
   
    @Test
    public void skip()
    {
        throw new SkipException("Skipped");
    }

}



After creating above testclasses your project look like below


  

testng.xml 

 
Right click on the project, select "TestNG" and click on "Convert to TestNG" to create the testng.xml and place under project folder. 

ANT build

Download the latest zip file from here
Extract and keep it in a easily accessible folder and follow below steps:


Click on This and Download this apache-ant -1.9 zip File


Extract it into Any Directory of your System
I have extract it into my E:folder.You can Extract it where you want.
Configure Path:
After Extracting Now you have to configure ant into your System.We need to set our Envirnment variable.Before setting enviornment variable let me show you My apache bin directory path.

Go to computer>Right click>properties>Advance systems Setting
Click on Envionment Variable
Click on new
Add a new System variable.Give the path upto your Bin folder of Apache

Now Set path apache path into the existing Directory.First Search Path and Click on Edit>Then edit path as ;%ANT_HOME%\bin.Now click on ok
Go to cmd prompt and Write ant -version.

Ant is installed succesfully.

build.xml and testng-results.xsl:


Click here to Download


Download testng-xslt jar  https://github.com/prashanth-sams/testng-xslt-1.1.2

Xslt

build.xml: 

open build.xml file and give the libs path (Where you have testng-xslt jar and Selenium jars).


Execute build.xml in Command prompt

Change the directory to your project path.

Type ant





Type "ant compile"
 


Type "ant run"


 
 Import testng-result.xslt 

import testng-result.xslt inside xslt package.



finally type "ant makexsltreports" 


After executing the above command the  xslt_Reports folder will  generate
 inside your project directory

 
Open index.html 




 

 Thanks.

If you doubt please leave your comments below.



 

No comments:

Post a Comment