How to trigger the testng.xml using ant?

Please guide,how to generate the build.xml file and how to trigger the testng.xml using this?

rajan Train Asked on January 17, 2015 in Selenium WebDriver.
Add Comment
1 Answer(s)

The below is a sample build.xml.  The below code should be in build.xml file

<?xml version=”1.0″ encoding=”iso-8859-1″?>
<!DOCTYPE project [
]>

<project name=”Sample Automation” default=”usage” basedir=”.”>

<!– ========== Initialize Properties =================================== –>
<property environment=”env”/>

<property name=”ws.home” value=”${basedir}”/>
<property name=”ws.jars” value=”D:/SeleniumWorkspace1/ProjectName/libs”/>
<property name=”test.dest” value=”${ws.home}/build”/>
<property name=”test.src” value=”${ws.home}/src”/>
<property name=”ng.result” value=”test-output”/>

<!–target name=”start-selenium-server”>
<java jar=”${ws.home}/lib/selenium-server.jar”/>
</target–>

<target name=”setClassPath” unless=”test.classpath”>
<path id=”classpath_jars”>
<fileset dir=”${ws.jars}” includes=”*.jar”/>
</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.6″
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=”TaihoAutomation”>
<xmlfileset dir=”${ws.home}” includes=”testng.xml”/>
</testng>
</target>

<target name=”usage”>
<echo>
ant run will execute the test
</echo>
</target>

<path id=”test.c”>
<fileset dir=”${ws.jars}” includes=”*.jar”/>
</path>

<!– ****************** targets not used ****************** –>

</project>

pradhakrishna284 Train Answered on January 22, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.