Tuesday, October 1, 2013

WebDriver: TestNG with ANT

Few posts back I explained how to use Maven with Webdriver and TestNG. Now let's see how to use ANT with WebDriver and TestNG.
<project name="WebDriverAntTestNG" default="run" basedir=".">
 <path id="libs">
  <!-- Include all the external Jar files -->
  <fileset dir="${basedir}\src\jars">
   <include name="*.jar"/>
  <!-- Include all the compile classes -->
  <fileset dir="bin">
   <include name = "**/*.class"/>
  <pathelement path="${basedir}\bin"/>
 <target name="run">
    <antcall target="init"/>
    <antcall target="compile"/>
    <antcall target="runTests"/>
   <!-- Delete old data and create new directories -->
  <target name="init" >
   <delete dir="bin" />
    <mkdir dir="bin"/>
    <delete dir="report" />
    <mkdir dir="report"/>
 <!-- Complies the java files -->
 <target name="compile">
    <javac includeantruntime="false" debug="true" srcdir="src" destdir="bin"   classpathref="libs" />

 <!-- Runs the file and generates Reportng report -->
 <target name="runTests" description="Running tests" >
  <echo>Running Tests...</echo>
    <taskdef resource="testngtasks" classpathref="libs"/>
    <testng outputDir="report"
   <classfileset dir="bin" includes="**/*.class" />


Targets Explained:

Run: This is main target, which will call all the below target in order.
Init: This target will delete the Bin an Report directory and will crate again in order to clean. 
Compile: This target will compile all the java classes. 
runTests: This target contain the TestNGTask which will all the testng tests. 


raghu said...

Very informative.. can you please post on how to generate xslt reports using WebDriver+TestNg+Ant

help is much appreciable.

Thanks, Raghu

Post a Comment