Monday, 26 May 2014

How to call testNG using Ant

<taskdef resource="testngtasks" classpath="testng.jar" />


<project name="runTestNG" basedir="." default="runTestNGTestCase">
<!--define your location of testng-6.8.jar--->
<path id="classpath.testNG">
<pathelement location="lib/selenium-2.39.0/libs/testng-6.8.jar"/>
</path>

<!--testng is external task...so, we need to define it using taskdef-->
<taskdef resource="testngtasks" classpathref="classpath.testNG"/>

<!--path declaration for all jars to be used for compilation and execution-->
<path id="lib.test">
<fileset dir ="lib">
<include name="**/*.jar"/>
</fileset>
</path>

<!--classpath declaration -->
<path id="classes.test.location">
<path location="bin" />
<fileset dir="lib" includes="**/*.jar" />
</path>

<!-- for compilation-->
<target name="compileFlipKart">
<delete dir="bin" includeEmptyDirs="true" failonerror="false"/>
<mkdir dir="bin" />
<javac srcdir="src" destdir="bin" classpathref="lib.test" />
</target>

<!--for execution of program with main method-->
<target name="runRunner" depends="compileFlipKart" >
<java fork="true" classname="self.learning.automate.test.Runner">
<classpath>
<path refid="lib.test" />
<path location="bin" />
</classpath>
</java>
</target>

<!--execution of test class using testNG-->
<target name="runTestNGTestCase">
<testng classpathref="classes.test.location" outputDir="test-output" useDefaultListeners="true" listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter">
<classfileset dir="bin" includes="**/TestFlipKarHomePage.class" />
 <sysproperty key="org.uncommons.reportng.title" value="My Test Report"/>
</testng>
</target>
</project>

No comments:

Post a Comment