I have developed a build.xml that can handle the the build of a test suite and do the reporting. It even send the report as mail. For reporting we are using TestNG-XSLT
<project name="Automation" default="clean" basedir=".">
<property name="build.dir" value="${basedir}/build"/>
<property name="lib.dir" value="${basedir}/lib"/>
<property name="src.dir" value="${basedir}/src"/>
<property name="browser" value="/home/nxavier/Downloads/firefox/firefox"/>
<target name="setClassPath">
<path id="classpath_jars">
<pathelement path="${basedir}/" />
<fileset dir="${lib.dir}" includes="*.jar" />
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars" />
</target>
<target name="loadTestNG" depends="setClassPath">
<taskdef resource="testngtasks" classpath="${test.classpath}"/>
</target>
<target name="init">
<mkdir dir="${build.dir}"/>
<tstamp>
<format property="timestamp" pattern="dd-MM-yyyy_(HH-mm-ss)"/>
</tstamp>
<property name="build.log.dir" location="${basedir}/buildlogs"/>
<mkdir dir="${build.log.dir}"/>
<property name="build.log.filename" value="build_${timestamp}.log"/>
<record name="${build.log.dir}/${build.log.filename}" loglevel="verbose" append="false"/>
<echo message="build logged to ${build.log.filename}"/>
</target>
<target name="clean">
<echo message="deleting existing build directory"/>
<delete dir="${build.dir}"/>
</target>
<target name="compile" depends="clean,init,setClassPath,loadTestNG">
<echo message="classpath:${test.classpath}"/>
<echo message="compiling.........."/>
<javac destdir="${build.dir}" srcdir="${src.dir}" classpath="${test.classpath}"/>
</target>
<target name="runTests" depends="compile">
<testng classpath="${test.classpath}:${build.dir}">
<xmlfileset dir="${basedir}" includes="Debug.xml"/>
</testng>
</target>
<target name="report" depends="runTests">
<delete dir="${basedir}/testng-xslt"/>
<mkdir dir="${basedir}/testng-xslt"/>
<xslt in="${basedir}/test-output/testng-results.xml"
style="${basedir}/src/xslt/testng-results.xsl" out="${basedir}/testng-xslt/index.html" processor="SaxonLiaison">
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir"/>
<param expression="true" name="testNGXslt.sortTestCaseLinks"/>
<param expression="FAIL,SKIP,PASS,BY_CLASS" name="testNgXslt.testDetailsFilter"/>
<param expression="true" name="testNgXslt.showRuntimeTotals"/>
<classpath refid="classpath_jars"/>
</xslt>
</target>
<target name="RunAndViewReport" depends="report">
<exec executable="${browser}" spawn="yes">
<arg line="'${basedir}/testng-xslt/index.html'" />
</exec>
</target>
<target name="sendMail" depends="RunAndViewReport">
<zip destfile="${basedir}/testng-xslt/Report.zip" basedir="${basedir}/testng-xslt"/>
<mail mailhost="smtp.gmail.com" mailport="465" subject="Notification of TESTNG build" ssl="false" user="tester@gmail.com" password="password">
<from address="tester@gmail.com"/>
<to address="tester@gmail.com"/>
<message>The build has finished. A details report of this build is aatched</message>
<attachments>
<fileset dir="testng-xslt">
<include name="**/*.zip"/>
</fileset>
</attachments>
</mail>
</target>
</project>
<project name="Automation" default="clean" basedir=".">
<property name="build.dir" value="${basedir}/build"/>
<property name="lib.dir" value="${basedir}/lib"/>
<property name="src.dir" value="${basedir}/src"/>
<property name="browser" value="/home/nxavier/Downloads/firefox/firefox"/>
<target name="setClassPath">
<path id="classpath_jars">
<pathelement path="${basedir}/" />
<fileset dir="${lib.dir}" includes="*.jar" />
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars" />
</target>
<target name="loadTestNG" depends="setClassPath">
<taskdef resource="testngtasks" classpath="${test.classpath}"/>
</target>
<target name="init">
<mkdir dir="${build.dir}"/>
<tstamp>
<format property="timestamp" pattern="dd-MM-yyyy_(HH-mm-ss)"/>
</tstamp>
<property name="build.log.dir" location="${basedir}/buildlogs"/>
<mkdir dir="${build.log.dir}"/>
<property name="build.log.filename" value="build_${timestamp}.log"/>
<record name="${build.log.dir}/${build.log.filename}" loglevel="verbose" append="false"/>
<echo message="build logged to ${build.log.filename}"/>
</target>
<target name="clean">
<echo message="deleting existing build directory"/>
<delete dir="${build.dir}"/>
</target>
<target name="compile" depends="clean,init,setClassPath,loadTestNG">
<echo message="classpath:${test.classpath}"/>
<echo message="compiling.........."/>
<javac destdir="${build.dir}" srcdir="${src.dir}" classpath="${test.classpath}"/>
</target>
<target name="runTests" depends="compile">
<testng classpath="${test.classpath}:${build.dir}">
<xmlfileset dir="${basedir}" includes="Debug.xml"/>
</testng>
</target>
<target name="report" depends="runTests">
<delete dir="${basedir}/testng-xslt"/>
<mkdir dir="${basedir}/testng-xslt"/>
<xslt in="${basedir}/test-output/testng-results.xml"
style="${basedir}/src/xslt/testng-results.xsl" out="${basedir}/testng-xslt/index.html" processor="SaxonLiaison">
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir"/>
<param expression="true" name="testNGXslt.sortTestCaseLinks"/>
<param expression="FAIL,SKIP,PASS,BY_CLASS" name="testNgXslt.testDetailsFilter"/>
<param expression="true" name="testNgXslt.showRuntimeTotals"/>
<classpath refid="classpath_jars"/>
</xslt>
</target>
<target name="RunAndViewReport" depends="report">
<exec executable="${browser}" spawn="yes">
<arg line="'${basedir}/testng-xslt/index.html'" />
</exec>
</target>
<target name="sendMail" depends="RunAndViewReport">
<zip destfile="${basedir}/testng-xslt/Report.zip" basedir="${basedir}/testng-xslt"/>
<mail mailhost="smtp.gmail.com" mailport="465" subject="Notification of TESTNG build" ssl="false" user="tester@gmail.com" password="password">
<from address="tester@gmail.com"/>
<to address="tester@gmail.com"/>
<message>The build has finished. A details report of this build is aatched</message>
<attachments>
<fileset dir="testng-xslt">
<include name="**/*.zip"/>
</fileset>
</attachments>
</mail>
</target>
</project>
Hi! Nice blog. I have a doubt, when i am using this build.xml for my project, i am getting a message that, couldn't find the library.
ReplyDeleteCan you help me with that..Do i need to add any jar file apart i have added, the jars mentioned in xml file too.
Buildfile: C:\Users\Amar\workspace\SeleniumAssertion\Build.xml
ReplyDeleteclean:
[echo] deleting existing build directory
clean:
[echo] deleting existing build directory
init:
[mkdir] Created dir: C:\Users\Amar\workspace\SeleniumAssertion\build
[echo] build logged to build_20-03-2013_(14-37-20).log
setClassPath:
BUILD FAILED
C:\Users\Amar\workspace\SeleniumAssertion\Build.xml:12: C:\Users\Amar\workspace\SeleniumAssertion\lib does not exist.
Total time: 373 milliseconds
This is the error.
Hi,
ReplyDeleteThe ANT build file works fine for Selenium RC but
I am having trouble in running the Webdriver(Selenium 2)
using the ANT build.xml file.
it works fine till compiling the java files and then when i run it simply skips all the test cases and not showing any error.
it is not even opening any browsers
so i want to know did the above build file work for Webdriver test case also?
please help me
HI Arun i am also facing the same issue ,if the issue is solved please let me know..
DeleteRaghu,
DeleteDid you specify testng.xml name in build.xml file of yours?
Thanks for the reply.Yeah i did mentioned it.,
DeleteThis comment has been removed by the author.
DeleteHi,
ReplyDeleteWhen iam using this Build.xml file in my webdriver Project.Iam getting only this message itself..
Buildfile: C:\Users\Admin\workspace\TestNG\src\Build.xml
clean:
[echo] deleting existing build directory
BUILD SUCCESSFUL
Total time: 282 milliseconds
I didn't get xslt reports and report mailing..
can u help me..
Hi NX,
ReplyDeletei tried the above code and was able to run the test suite without any errors. But i am not able to see the zip file created and email sent. Kindly advise.
Regards,
Sachin
Hi,
ReplyDeleteI am getting below error. Kindly support
Buildfile: D:\Java Workspace\ExampleAnt\Build.xml
setClassPath:
setClassPath:
loadTestNG:
init:
[mkdir] Created dir: D:\Java Workspace\ExampleAnt\build
[echo] build logged to build_09-12-2014_(12-18-31).log
clean:
[echo] deleting existing build directory
[delete] Deleting directory D:\Java Workspace\ExampleAnt\build
clean:
[echo] deleting existing build directory
init:
[mkdir] Created dir: D:\Java Workspace\ExampleAnt\build
[echo] build logged to build_09-12-2014_(12-18-31).log
setClassPath:
loadTestNG:
compile:
[echo] classpath:D:\Java Workspace\ExampleAnt:D:\Java Workspace\ExampleAnt\lib\testng-6.8.5.jar
[echo] compiling..........
[javac] D:\Java Workspace\ExampleAnt\Build.xml:35: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
BUILD FAILED
D:\Java Workspace\ExampleAnt\Build.xml:35: Class not found: javac1.8
Total time: 313 milliseconds
Hi Neela,
DeleteCan you please try renaming the folder 'Java Workspac' to 'JavaWorkspac' and try the build..
Hi NX,
ReplyDeleteThanks for reply.Error displayed on executing BUILD.xml in eclipse
Error:
Buildfile: D:\Java Workspace\ExampleAnt\Build.xml
init:
[echo] build logged to build_09-12-2014_(18-14-19).log
setClassPath:
loadTestNG:
setClassPath:
clean:
[echo] deleting existing build directory
[delete] Deleting directory D:\Java Workspace\ExampleAnt\build
clean:
[echo] deleting existing build directory
init:
[mkdir] Created dir: D:\Java Workspace\ExampleAnt\build
[echo] build logged to build_09-12-2014_(18-14-19).log
setClassPath:
loadTestNG:
compile:
[echo] classpath:D:\Java Workspace\ExampleAnt:D:\Java Workspace\ExampleAnt\lib\testng-6.8.5.jar
[echo] compiling..........
[javac] D:\Java Workspace\ExampleAnt\Build.xml:35: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
BUILD FAILED
D:\Java Workspace\ExampleAnt\Build.xml:35: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre8"
Total time: 345 milliseconds
Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.
ReplyDeleterpa training in bangalore
best rpa training in bangalore
RPA training in bangalore
RPA courses in bangalore
This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.
ReplyDeleteI like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
Java training in Chennai
Java training in Bangalore
Java online training
Java training in Pune
Really it was an awesome article about JAVA, very interesting to read.You have provided an nice article,Thanks for sharing.
ReplyDeleteJava training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
I have read your blog and i got a very useful and knowledgeable information from your blog. its really a very nice article..thanks lot!!
ReplyDeleteandroid training in chennai
android online training in chennai
android training in bangalore
android training in hyderabad
android Training in coimbatore
android training
android online training
Smm panel
ReplyDeletesmm panel
iş ilanları
İNSTAGRAM TAKİPÇİ SATIN AL
hirdavatciburada.com
beyazesyateknikservisi.com.tr
servis
tiktok jeton hilesi
tuzla toshiba klima servisi
ReplyDeletekartal lg klima servisi
ümraniye lg klima servisi
kartal alarko carrier klima servisi
ümraniye alarko carrier klima servisi
kartal daikin klima servisi
ümraniye daikin klima servisi
beykoz toshiba klima servisi
üsküdar toshiba klima servisi