Wednesday, May 23, 2012

Execute a suite file using Ant

Suite file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
 <suite name="Suite1" verbose="1" >
  <test name="Regression1" preserve-order="true">
    <classes>
   <class name="mytests.First">
    </class>
    </classes>
    </test>
</suite>

Build.xml

<project name="selenium-demo" default="compile" basedir=".">

    <property name="build.dir" value="build" />
    <property name="src.dir" value="src"/>
    <property name="lib.dir" value="lib"/>
    <property name="reports.dir" value="report"/>
    <property name="xml" value="Sample.xml"/>

    <path id="classpath">
        <pathelement location="${build.dir}/classes"/>
        <fileset dir="${lib.dir}" includes="**/*.jar"/>
    </path>

 <!--   <taskdef name="testng" classname="com.beust.testng.TestNGAntTask" classpathref="classpath"/>
-->    <taskdef resource="testngtasks" classpathref="classpath"/>

    <target name="compile">
        <delete dir="${build.dir}"/>
        <mkdir dir="${build.dir}/classes"/>
        <echo message="Compiling tests" />
        <javac srcdir="${src.dir}" destdir="${build.dir}/classes"  executable="javac" classpathref="classpath">
            <classpath refid="classpath"/>
        </javac>
    </target>

    <target name="run_tests" depends="compile">
       <echo message="running tests" />
       <testng classpathref="classpath" haltOnfailure="true">
               <xmlfileset file="${xml}" />
            <sysproperty key="env" value="${env}"/>
            <sysproperty key="driver" value="${driver}"/>
       </testng>
    </target>

</project>

No comments:

Post a Comment