How to generate XSLT Report using testNG and ANT ?

Why should we go for TestNg?

Answer :-

  • TestNg annotations are very useful to control the test cases to be executed.
  • TestNg generates a very flashy report called as XSLT report with the help of ANT.
XSLT Report :-




Setting Up TestNG-XSLT Report generator and ANT for Selenium Projects


[Adding TestNG-XSLT report generator package to the Project]

1. Download TestNG-XSLT package from TestNG-XSLT Package
2. Extract the package and copy the JAR files in LIB folder to the Lib Folder of your Project.

[Setting up ANT]

1. Download ANT from http://ant.apache.org/bindownload.cgi
2. Extract the ZIP
3. System Properties -> Advanced System Settings -> Enviroment Variables
4. Create a New System Varable Variable Name :'ANT_HOME' and Value: ANT Path (The Location where you've extracted the contents of .ZIP)
5. Find the variable named  "Path" under System Variables and edit its value as follows.
        append ";" at the end of the value and add "D:\eclipse\Selenium\apache-ant-1.9.1\bin" (The Location where you've kept the extracted folder of ANT)

6. Define a Build.XML for ANT


Sample Build.XML

<project name="Selenium Best Practices" basedir=".">
<taskdef name="testng" classname="org.testng.TestNGAntTask">
   <classpath>
     <pathelement location="lib/testng-6.8.8.jar"/>
   </classpath>
 </taskdef>
    <property name="LIB" value="${basedir}/lib" />
    <property name="BIN" value="${basedir}/bin" />
<property name="SRC" value="${basedir}/src" />

    <path id="master-classpath">
    <pathelement location="${BIN}"/>
       <fileset dir="${LIB}" includes="**/*.jar"/>
    </path>

<target name="clean" >
     <delete>
        <fileset dir="${BIN}" includes="**/*.class" />
     </delete>

<delete dir="${basedir}/test-output">
       </delete>
       <mkdir dir="${basedir}/test-output">
       </mkdir>
  </target>

<target name="compile">
     <javac srcdir="${SRC}" destdir="${BIN}">
      <classpath refid="master-classpath"> 
      </classpath>
     </javac>
  </target>

<target name="run">
<testng outputdir="${basedir}/test-output" classpathref="master-classpath"> 
<xmlfileset dir="${basedir}" includes="testng.xml"/> 
   </testng>
  </target>
     
    <target name="generateReport">
        <delete dir="${basedir}/testng-xslt">
        </delete>
        <mkdir dir="${basedir}/testng-xslt">
        </mkdir>
        <xslt in="${basedir}/test-output/testng-results.xml" style="${basedir}/resources/testng-results.xsl" out="${basedir}/testng-xslt/index.html">
            <param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />
            <param expression="true" name="testNgXslt.sortTestCaseLinks" />
            <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
            <param expression="true" name="testNgXslt.showRuntimeTotals" />
            <classpath refid="master-classpath">
            </classpath>
        </xslt>
    </target>

</project> 


7. Place the Build.XML in your project Folder
8. Copy the "testng-results.XSL" from the TestNG package to your base directory i.e, your project folder. "testng-results.XSL" will be available at [..\testng-xslt-1.1.2-master\src\main\resources] 
9. Launch Command prompt, Go to your Project Location, for Instance "D:\SeleniumProjects\TestAutomation>" and type "ant clean compile run generateReport"
10. Find the TestNG-XSLT report (index.html) in the target Location specified in the Build.XML. In the above example it is specified as "testng-xslt"


Comments

Popular posts from this blog

Encoding and Decoding in Selenium using Base64 Class of Java

Parallel Execution In TestNG Framework Using ThreadLocal Concept

How to handle calendar or date picker using dynamic XPATH?