Emailing XSLT Report in WebDriver/Java Using ant build.xml automatically

Emailing XSLT Report in WebDriver/Java Using ant build.xml automatically

Emailing XSLT Report in WebDriver/Java Using ant build.xml automatically
1- Read installation of Ant on your system from here

2- Configuration for XSLT Report 1- Download testng-xslt-1.1.2-master.zip file from this location 2- Unzip testng-xslt-1.1.2-master.zip file 3- Copy all jar files and place them in jar library folder in your project. 4- Copy the testng-results.xsl from the testng-xslt folder(path: XSLT jartestng-xslt-1.1.2-mastertestng-xslt-1.1.2-mastersrcmainresources) and place in your project folder. 5- Create build.xml in your project under eclipse. To read how to create build.xml read here 6- Modify xml code in build.xml Here is the build.xml to create xslt report ===================================build.xml======================= <project name="Automation" default="makexsltreports" basedir="."> <!-- Defining property --> <property name="project.dir" value="${basedir}"/> <property name="build.dir" value="${basedir}/build"/> <property name="jar.dir" value="${basedir}/Lib"/> <property name="src.dir" value="${basedir}/src"/> <property name="ng.result" value="test-output"/> <!-- Setting Classpath for jar files --> <target name="setClassPath"> <path id="classpath_jars"> <pathelement path="${basedir}/" /> <fileset dir="${jar.dir}"> <include name="*.jar"/> </fileset> </path> <pathconvert pathsep=":" property="test.classpath" refid="classpath_jars" /> </target> <!-- Loading Testng --> <target name="loadTestNG" depends="setClassPath" > <taskdef resource="testngtasks" classpath="${test.classpath}"/> </target> <!-- Deleting directories --> <target name="clean"> <echo message="deleting existing build directory"/> <delete dir="${build.dir}"/> </target> <!-- Creating build folder to store compiled classes --> <target name="init" depends="clean,setClassPath"> <mkdir dir="${build.dir}"/> </target> <!-- Compiling java files --> <target name="compile" depends="clean,init,setClassPath,loadTestNG"> <echo message=""/> <echo message="compiling.........."/> <javac destdir="${build.dir}" srcdir="${src.dir}" includeantruntime="false" classpath="${test.classpath}"/> </target> <target name="run" depends="compile"> <testng classpath="${test.classpath}:${build.dir}"> <xmlfileset dir="${basedir}" includes="testng.xml"/> </testng> </target> <!-- adding XSLT report target to produce XSLT report --> <target name="makexsltreports" depends="run"> <delete dir="${project.dir}/XSLT_Reports/output"> </delete> <mkdir dir="${project.dir}/XSLT_Reports/output"/> <xslt in="${ng.result}/testng-results.xml" style="src/dummy/testng-results.xsl" out="${project.dir}/XSLT_Reports/output/index.html" classpathref="classpath_jars" processor="SaxonLiaison"> <param name="testNgXslt.outputDir" expression="${project.dir}/XSLT_Reports/output/"/> <param name="testNgXslt.showRuntimeTotals" expression="true"/> <param expression="true" name="testNgXslt.sortTestCaseLinks" /> <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" /> </xslt> </target> </project> ===========End of build.xml====================== Since in above build.xml we have used testng it means we need to add testng.xml(you may put nay name of you xml) ===============testng.xml=====================

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Ant Suite">
       <test name="Generictest">
       <packages> <package name="dummy" /> </packages>                                                             
       </test>
 </suite>
======================testng.xml============== 7- Launch Command prompt, Go to your Project Location, for Instance  type "ant makexsltreports" 8. Find the TestNG-XSLT report (index.html) in the target Location specified in the Build.XML.
3- Sending mail through ant 1- Download javax.mail.jar.zip from here  and javax.activation.jar.zip from here 2- Unzip both file 3- Copy javax.mail.jar and javax.activation.jar and go to you Ant home folder(Where you have unziped your Ant zip file in your directory), search lib folder and paste both jar files. 4- Come to build.xml file and add line Here I am adding makexsltreports as dependencies since we are trying to send the zipped report of XSLT in to mail
======================Javamail api integration in ant=================
<!-- using javax.mail.jar and javax.activation.jar trying to send report as zip file --> <target name="sendMail" depends="makexsltreports"> <!-- Compressing all the output file of XSLT report --> <zip destfile="${project.dir}/XSLT_Reports/output.zip" basedir="${project.dir}/XSLT_Reports/output" /> <mail tolist="List of mail id separated with comma" from="username@gmail.com" subject="Email subject" mailhost="smtp.gmail.com" mailport="465" ssl="true" user="username@gmail.com" password="password"> <attachments> <fileset dir="${project.dir}/XSLT_Reports/"> <include name="**/*.zip"/> </fileset> </attachments> </mail> </target> =========================================================== So here is complete build.xml through which we can generate xslt report and can also send zipped report on some maild ids. <project name="Automation" default="sendMail" basedir="."> <!-- Defining property --> <property name="project.dir" value="${basedir}"/> <property name="build.dir" value="${basedir}/build"/> <property name="jar.dir" value="${basedir}/Lib"/> <property name="src.dir" value="${basedir}/src"/> <property name="ng.result" value="test-output"/> <!-- Setting Classpath for jar files --> <target name="setClassPath"> <path id="classpath_jars"> <pathelement path="${basedir}/" /> <fileset dir="${jar.dir}"> <include name="*.jar"/> </fileset> </path> <pathconvert pathsep=":" property="test.classpath" refid="classpath_jars" /> </target> <!-- Loading Testng --> <target name="loadTestNG" depends="setClassPath" > <taskdef resource="testngtasks" classpath="${test.classpath}"/> </target> <!-- Deleting directories --> <target name="clean"> <echo message="deleting existing build directory"/> <delete dir="${build.dir}"/> </target> <!-- Creating build folder to store compiled classes --> <target name="init" depends="clean,setClassPath"> <mkdir dir="${build.dir}"/> </target> <!-- Compiling java files --> <target name="compile" depends="clean,init,setClassPath,loadTestNG"> <echo message=""/> <echo message="compiling.........."/> <javac destdir="${build.dir}" srcdir="${src.dir}" includeantruntime="false" classpath="${test.classpath}"/> </target> <target name="run" depends="compile"> <testng classpath="${test.classpath}:${build.dir}"> <xmlfileset dir="${basedir}" includes="testng.xml"/> </testng> </target> <!-- adding XSLT report target to produce XSLT report --> <target name="makexsltreports" depends="run"> <delete dir="${project.dir}/XSLT_Reports/output"> </delete> <mkdir dir="${project.dir}/XSLT_Reports/output"/> <xslt in="${ng.result}/testng-results.xml" style="src/dummy/testng-results.xsl"out="${project.dir}/XSLT_Reports/output/index.html" classpathref="classpath_jars" processor="SaxonLiaison"> <param name="testNgXslt.outputDir" expression="${project.dir}/XSLT_Reports/output/"/><param name="testNgXslt.showRuntimeTotals" expression="true"/> <param expression="true" name="testNgXslt.sortTestCaseLinks" /> <param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" /> </xslt> </target> <!-- using javax.mail.jar and javax.activation.jar trying to send report as zip file --> <target name="sendMail" depends="makexsltreports"> <zip destfile="${project.dir}/XSLT_Reports/output.zip" basedir="${project.dir}/XSLT_Reports/output" /> <mail tolist="username@gmail.com" from="username@gmail.com" subject="Email subject" mailhost="smtp.gmail.com" mailport="465" ssl="true" user="username@gmail.com" password="password"> <attachments> <fileset dir="${project.dir}/XSLT_Reports/"> <include name="**/*.zip"/> </fileset> </attachments> </mail> </target> </project> here in this example I have taken gmail.com but you may take some other SMTP server and port according to your need.