Simple build.xml Code for TestNG
Below is the code to run TestNG suite using build.xml.Note that this does not generate xslt report or you can say below code is a cleaned up version without xslt reporting.(You can also auto generate using Eclipse :
File -> Export -> General -> Ant Buildfiles
and specify the file name, project, etc. )Steps below:
- Open Eclipse >Navigate to your project.
- On your project folder > Right ck > Create New File and Name it as "build.xml"
- Copy paste the below code with required modifications.
Code Below:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>
<project name="Learning TestNG" default="usage" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property name="work.home" value="${basedir}"/>
<property name="work.jars" value="D:\shared\selenium_tools\selenium-java-2.39.0\selenium-2.39.0\libs"/><!--Change value here , to locations where all Jar files are located-->
<property name="test.dest" value="${work.home}/build"/>
<property name="test.src" value="${work.home}/src/"/><!--Folder which contains Java files , folder itself might contain many packages-->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${work.jars}" includes="*.jar"/>
</path>
<path id = "log4j">
<fileset dir = "${log4j.dir}">
<include name = "log4j.properties" />
</fileset>
</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="suite1">
<xmlfileset dir="${work.home}" includes="testng.xml"/>
</testng>
</target>
<target name="usage">
<echo>
ant run will execute the test
</echo>
</target>
<path id="test.c">
<fileset dir="${work.jars}" includes="*.jar"/>
</path>
<!-- ****************** targets not used ****************** -->
</project>
No comments:
Post a Comment