Showing posts with label ANT. Show all posts
Showing posts with label ANT. Show all posts

Thursday, April 19, 2012

ANT and Build.xml File for the Selenium Project

LinkShare Money Mania - Do Not Delete- Untitled 2
Ant Build for the Selenium Java Project:
It is open source tool.
Ant can be used to generate the html report and it is run in your same project it can be run it through cmd prompt.
How to make Build .xml file?
1. Right click on the project
2. Go to the new>>file gives the filename as build.xml
Here is my Project Setup for the Ant



Here is Build.xml file Code:

<project name="Selenium" default="usage" basedir=".">
    <property environment="env"/>

  
  <property name="ws.build" value="${basedir}"/>
  <property name="ws.jar" value="D:/Jar file of the selenium"/>
  <property name="test.dest" value="${ws.build}/Build"/>
  <property name="test.src" value="${ws.build}/src"/>
  <property name="test.report" value="D:/Report1"/>
    <path id="testcase.path">
<pathelement location="${test.dest}"/>
<fileset dir="${ws.jar}">
<include name="*.jar"/>
</fileset>
</path>
<path id="test.classpath">
<pathelement location="${ws.jar}"/>
</path>
   <target name="setClassPath" unless="test.classpath">
    <path id="classpath_jars">
    <fileset dir="${ws.jar}" 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>

<target name="all">
</target>
  <target name="clean">
    <delete dir="${test.dest}"/>
    </target>

  <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.7"
classpath="${test.classpath}"
>
</javac>
 </target>
<target name="build" depends="init">
</target>
<target name="usage">
<echo>
ant run exceute
</echo>
</target>
<path id="test.c">
<fileset dir="${ws.jar}" includes="*.jar"/>
</path>
  <target name="run" >
   <delete includeemptydirs="true" quiet="true">
   <fileset dir="${test.report}" includes="**/*"/>
   </delete>
   <java jar ="${ws.jar}" fork="true" spawn="true"/>
   <junit fork="yes" haltonfailure="no" printsummary="yes">
   <classpath refid="testcase.path" />
   <batchtest todir ="${test.report}" fork="true">
   <fileset dir="${test.dest}">
   <include name="sel.Testcases/FirstTest.class"/>
   <!-- <include name="Testcase/SecoandTest.class"/> 
   -->
   <!-- <include name="Testcase/ThirdTest.class"/>
   -->
   </fileset>
   </batchtest>
   <formatter type="xml"/>
      <classpath refid="testcase.path"/>
   </junit>
   <junitreport todir="${test.report}">
   <fileset dir="${test.report}">
   <include name="**.xml"/>
   </fileset>
   <report todir="${test.report}"/>
   </junitreport>
      </target>


</project>

Related Documents:
ANT Terminology
How to configure ANT in System?
How to make build.xml file?





Thursday, March 8, 2012

What is "ANT"?


It is open source tool.
Ant can be used to generate the html report and it is run in your same project it can be run it through cmd prompt but sometime you want to run the project in UNIX server... that time ANT specially  use
It is use for the build in the cmd prompt or in shell environment.
It is implemented in JAVA..It's compile the source code,run unit test.
Ant build file written in the XML.

Download the ANT latest Version from following link:

How to make build.xml file?


1. Right click on the project
2. Go to the new>>file gives the filename as build.xml

Eg:
<project name="MyProject" default="usage" basedir=".">
<description>
     creating the simple build xml file
</description>
<!-- Set global property for this build file -->
<property name="src" value="${basedir}"/>
  <property name="jar" value="C:/Selenium/Jar file"/>
  <property name="build" value="build"/>
<!---Creating the Init Target>
<target name="init" >
<!--create timestamp--->
<tstamp/>
<!--create the build directory-->
<mkdir dir="${"build"}"/>
</target>
<!---Creating the Compile Target>
<target name="compile" depends="init" >
<!--compile the java source code from src to build dir--->
<javac srcdir="${"src"}" destdir="${"build"}"/>
</target>

<!---Creating the Dist Target>
<target name="dist" depends="compile" >
<mkdir dir="${"dist"}/lib"/>
<!---Put everything in ${build} into the myproject >
<jar jarfile="${"dist"}/lib/${ant.project.name}-${DSTAMP.jar}" basedir="${C:/project}"/>
</target>
<!---Creating the Clean Target>
<target name="clean" >
<delete dir="${"build"}"/>
<delete dir="${"dist"}"/>
</target>
</project>



  

ANT Terminology


Lets First understand ANT Terminology:
1.<Project> : 
   It is top level element in the ANT Script
   It is has three optional attributes:
   a.name b.default c.basedir
   a.name:  need to define the name of the project
   b.default: default target use when no other target to supplied
   c.basedir: It is where all path calculation are done
2.Target:
   It is set of the task which you want to be executed.
   Each project can be define zero or more target.Target can be depend on the another target.
   Project can be have zero or more targets. when no target is given the project use the default target.
   When the starting the ANT you can choose whichever target you want to be executed. 
   The main Targets are:
   1.Clean:  Clean up
   2.Compile: Compile the source code
   3.Dist: Generate the distribution
 3.Task: 
    It is piece of the code which can be executed.It has multiple attributes.
    There are so many task written for ANT.
    ANT Task:
    1.File Task:  File task are copy,concat,mkdir,delete,get,replace,move,tempfile etc.
    2.Compile Task: Compile task are javac,apt,rmic
    3.Archive Task: Archive task are zip-unzip,jar-unjar,war-unwar 
    4.Testing Task:  Teasting Task are junit,junitreport
    5.Property Task: Property task are dirname,loadfile,propertyfile,uptodate
    6.There are some other task are there like echo,javadoc,sql 
4.Properties:
   It has a name and a value,it's case sensitive.
   The property name specify between the "${"property-name"}" and attribute value too.