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"/>
  </fileset>
  <!-- Include all the compile classes -->
  <fileset dir="bin">
   <include name = "**/*.class"/>
  </fileset>
  <pathelement path="${basedir}\bin"/>
  </path>
 
 <target name="run">
    <antcall target="init"/>
    <antcall target="compile"/>
    <antcall target="runTests"/>
  </target>
 
   <!-- Delete old data and create new directories -->
  <target name="init" >
   <echo>Initlizing...</echo>
   <delete dir="bin" />
    <mkdir dir="bin"/>
    <delete dir="report" />
    <mkdir dir="report"/>
    
  </target>
 
 <!-- Complies the java files -->
 <target name="compile">
    <echo>Compiling...</echo>
    <javac includeantruntime="false" debug="true" srcdir="src" destdir="bin"   classpathref="libs" />
  </target>

 <!-- 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"
    haltonfailure="true"
    classpathref="libs"
      >
   <classfileset dir="bin" includes="**/*.class" />
    </testng>
  </target>

</project>

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. 


1 comments:

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