XSL
stands for Extensible Style sheet Language, and is a style sheet
Language
for XML documents. XSLT stands for XSL Transformations.
In
this tutorial you will learn how to use XSLT to transform XML
Documents
into other formats, like XHTML. XSLT which gives good graphical generated
reports.
Steps for generating
reports:
1. Download
ANT http://ant.apache.org/bindownload.cgi
2. Configure
environment variable for ant
User variable
variable name: ANT_HOME
variable value: C:\Program Files\Java\apache-ant-1.9.1
variable name: ANT_HOME
variable value: C:\Program Files\Java\apache-ant-1.9.1
System variable
variable name: Path
variable value: C:\Program Files\Java\apache-ant-1.9.1\bin
Check ANT version
cmd > ant -version
variable name: Path
variable value: C:\Program Files\Java\apache-ant-1.9.1\bin
Check ANT version
cmd > ant -version
2.Go to src folder
3. Create a folder name as "xslt"
4. Download https://github.com/prashanth-sams/testng-xslt-1.1.2
5.Unzip it
6.Go to fallowing directory "testng-xslt-1.1.1\testng-xslt-1.1.1\src\main\resources"
7. Copy the "testng-results.xsl" and keep in "xslt"
8.
Now copy the saxon.jar file from fallowing path "testng-xslt-1.1.1\testng-xslt-1.1.1\lib".
9. place it your project folder.
9. place it your project folder.
9.
Create build.xml file http://seleniumtwo.blogspot.in/2013/07/buildxml-configuration.html
10.
Modify your build.xml of ant and add the following target to it.
<?xml
version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE
project [
]>
<project
name="TestNG" default="usage" basedir=".">
<!--
========== Initialize Properties =================================== -->
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars"
value="F:\1"/>
<property name="test.dest"
value="${ws.home}/build"/>
<property name="test.src"
value="${ws.home}/src"/>
<property
name="ng.result" value="test-output"/>
<!--target name="start-selenium-server">
<java
jar="${ws.home}/lib/selenium-server.jar"/>
</target-->
<target name="setClassPath"
unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}"
includes="*.jar"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars"/>
</target>
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time"
pattern="MM/dd/yyyy hh:mm aa" />
</tstamp>
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition>
<taskdef name="testng"
classpath="${test.classpath}"
classname="org.testng.TestNGAntTask" />
</target>
<!-- all -->
<target name="all">
</target>
<!-- clean -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compile -->
<target name="compile" depends="init, clean"
>
<delete
includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}"
includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir
dir="${test.dest}"/>
<echo message="classpath------:
${test.classpath}"/>
<echo message="compiling..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.5"
classpath="${test.classpath}"
>
</javac>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<!-- run -->
<target name="run" depends="compile">
<testng
classpath="${test.classpath}:${test.dest}" suitename="sivaprasad">
<xmlfileset dir="${ws.home}"
includes="testng.xml"/>
</testng>
<!--
<testng
classpath="${test.classpath}:${test.dest}"
groups="fast">
<classfileset
dir="${test.dest}" includes="example1/*.class"/>
</testng>
-->
</target>
<target name="usage">
<echo>
ant run will execute the test
</echo>
</target>
<path id="test.c">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<target
name="makexsltreports">
<mkdir dir="${ws.home}/XSLT_Reports/output"/>
<xslt in="${ng.result}/testng-results.xml"
style="src/xslt/testng-results.xsl"
<param name="testNgXslt.outputDir" expression="${ws.home}/XSLT_Reports/output/"/>
<param name="testNgXslt.showRuntimeTotals"
expression="true"/>
</xslt>
</target>
<!-- ****************** targets not used ****************** -->
</project>
NOTE: 1. instead of
"F:\1" give your own jar files path
2. Instead of
"testng.xml" replace your xml
6.
Create testng.xml file in your project with the following script for
TestNG execution
<?xml
version="1.0" encoding="UTF-8"?>
<suite
name="Ant Suite">
<test name="SP Kandua">
<classes>
<class name="sample.Xlstreport"
></class>
</classes>
</test>
</suite>
7. Now
run from the command prompt
ant makexsltreports
We will get results like below image
Hi..
ReplyDeleteHow to run from the command Prompt..? Can you please help me on this..
go to your project location and enter ant makexsltreports
DeleteInformative post ....go head with great work !!!!!!!!!!!!
ReplyDeleteHi,Nice Work.Please keep up the good work.Please create more posts w.r.t selenium and webdriver and its related technologies.All the best.MAY GOD BLESS YOU...
ReplyDeleteIn the above build.xml ,how do i store the results of Testng in sepereate Time -stamped folders so that the previous results are not overwritten by new ones .
ReplyDeletefrom where to downlaod the jar files ?
ReplyDeleteAbove i have mentioned path of jar files click on 4 th step .....it will navigate to google docs there u can find the jars..click on file tab and download files .....
Deletei am getting class not found exception:Saxonliason
ReplyDeleteHi
ReplyDeleteSivaprasad Kandula
This is Ramaniranjan
I got this error "taskdef class org.testng.testnganttask cannot be found using the classloader antclassloader" at complie time when compile form cmd
please help me as soon as possible
Thanks
Hi Sivaprasad,
ReplyDeleteYou mentioned "instead of "F:\1" give your own jar files path", which jar file u r referring here??
Hi Siva,
ReplyDeleteWhen i trying build project through build.xml i got some error like
testng-results.xsl:411: Fatal Error! Failed to create output file file:////./XSLT_Reports/output/style.css Cause: java.io.IOException: The system cannot find the path specified
Please any one help for me??
Why I don't have image display output report,can you help me
ReplyDelete