XSLT reports using TestNG through Ant





Selenium – Use Ant to Generate XSLT Reports

To generate HTML XSLT reports using ant that we need to follow 6 steps

  1. Create build.xml file
  2. Setup library jar files
  3. Compile Script
  4. Task define for ant and testNg
  5. Execute script
  6. Generate XSLT reports
Create build.xml file
  • Now go to eclipse and create build.xml file to your selenium project root level .
  • add below script into build.xml file
<project name="Project Name"basedir="." >
<!-- Code -->
</project>


Setup library jar files
<project name="Project Name"basedir="." >
<!-- Create class path for jar files-->
<path id="jarfiles">
<!-- .class files location-->
<pathelement location="${basedir}/bin"/>
<!-- jar files location-->
<fileset dir="${basedir}/libs" >
<!-- include .jar files-->
<include name="*.jar"/>
</fileset>
</path>
</project>

Compile Script
<project name="Project Name"basedir="." >
<!-- Create target compile , name can be anything-->
<target name="compile">
<!-- delette bin folder in project-->
<delete dir="${basedir}/bin"/>
<!-- create bin folder in project-->
<mkdir dir="${basedir}/bin"/>
<!-- compile .java files to .class file , files will be stored in bin folder-->
<javac srcdir="${basedir}/src" destdir="${basedir}/bin" classpathref="jarfiles" />
</target>
<!-- close target-->
</project>

Task define for ant and testNg
<project name="Project Name"basedir="." >
<!-- create class path testng file-->
<taskdef name="krishna" classname="org.testng.TestNGAntTask">
<classpath>
<!-- locate testng jar file-->
<pathelement location="${basedir}/Libs/testng-6.8.5.jar"/>
</classpath>
</taskdef>
</project>
Execute script
<project name="Project Name"basedir="." >
<!-- run taget starts, depends on compile-->
<target name="testng" depends="compile">
<!-- create reports folder in project-->
<mkdir dir="${basedir}/reports"/>
<krishna outputdir="${basedir}/reports" classpathref="jarfiles">
<!-- execute testng.xml file-->
<xmlfileset dir="${basedir}" includes="testNg.xml" >
</xmlfileset>
</krishna>
</target>
</project>

Generate XSLT reports
<project name="Project Name"basedir="." >
<target name="makexsltreports">
<mkdir dir="${ws.home}/XSLT_Reports/output"/>
<xslt in="${ng.result}/testng-results.xml" style="${basedir}/testng-results.xsl"
out="${ws.home}/XSLT_Reports/output/index.html" classpathref="jarfiles" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${ws.home}/XSLT_Reports/output/"/>
<param name="testNgXslt.showRuntimeTotals" expression="true"/>
</xslt>
</target>
</project>

  • In this Build.xml file give the path where you copied all the required jar file.(Copy all the required jar files in any of the Libs folder and mention that path)
  • Now go to command prompt and type > ant clean
  • It will clean all the required files related to ant.
  • Now type > ant compile
  • It will compile your code
  • Now type >ant run 
It will run your program and will generate HTML reports.

Generating selenium reports using TestNG-xslt through Ant

TestNG-xslt generates user friendly reports using the TestNG results output (testng-results.xml). Its uses the pure XSL for report generation and Saxon as an XSL2.0 implementation

For generating testng-xslt report for your project do the following:

1. Download the testng-xslt

2. Unzip and copy the testng-results.xsl from the testng-xslt folder(testng-xslt-

3. Now go to command prompt and follow below steps to generate XSLT reports.

It will clean all the required files related to ant.

4. Now type > ant compile

It will compile your code

5. Now type >ant testng

It will run your program.

6. Now type >ant makexsltreports

It will generate xslt reports as below