Tuesday 16 October 2012

(Selenium webdriver + Ant + Testng) Build.xml sample file to be used

I have got this build.xml from one of the sites...
and have customised it a bit to get it working.


${basedir} refers to project directory

I have updated path to suite.xml file in below code
I have also added below code to remove existing test output and create each one every time tests are run.

<target name="runTests" depends="compile"> <echo message="${basedir}"/>
<delete dir="${basedir}/test-output"/>
<mkdir dir="${basedir}/test-output"/> 
 <testng classpath="${test.classpath}:${build.dir}"> <xmlfileset dir="${basedir}/src/testpackage/" includes="suite1.xml"/> </testng> </target>

 

<
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}" includeantruntime="false" classpath="${test.classpath}"/>
</target>
<target name="runTests" depends="compile">
<echo message="${basedir}"/>
<delete dir="${basedir}/test-output"/>
<mkdir dir="${basedir}/test-output"/>
<testng classpath="${test.classpath}:${build.dir}">
<xmlfileset dir="${basedir}/src/testpackage/" includes="suite1.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>

Suite.xml must be written as per testng guidelines.
I haven't verified email functionality

I will make another post explaining how to use this build xml and run it from command line

No comments:

Post a Comment