ANT Build Tool

  • Ant is a build tool which is used to create a build for a particular application.
  • Ant is a platform-independent scripting tool.
  • Ant installation consists of downloading the files, adding the class libraries to the classpath, and adding the Ant binaries to the path.
  •  By default ant triggers build.xml. Apache Ant is a Java library and command-line tool that help building software.

Steps to download ANT and install ANT

1) Download the latest apache ant from this link     https://ant.apache.org/bindownload.cgi
2) Extract the downloaded apache ant
3) Then Copy the folder and  go to C:  drive and paste it.
4) Set up Environment variable by giving bin folder path.
Go to my computer -> right click -> properties -> advanced system setting -> environment variables -> under system variables -> search for variable 'path' and click on edit.
5)  Go to C: drive>>open apache >>and go to till bin folder then copy the complete path.
6) Under environment variable go to end of line insert ; (semi-colon) and paste the path. Click on Ok just one time.
7) Under system variable click on new, and give the variable name as ANT_HOME. Under variable value: paste the path till parent of bin(don't open bin folder). Again click on Ok just one time.
8) Under system variable again click on new, give the variable name as JAVA_HOME. Under variable value paste the path till the parent of bin folder of JDK. (from Program Files(x86) or Program Files).
9) Click on 3 times ok.
10) Verify  ANT is installed or not.


How to verify Ant installed or not?
Ans-  go to cmd and type -> ant -version
You will see some ANT installed version.

build.xml (For execution of automation script)


<project name="Your project Name" basedir="." default="runTests"> 
    <property name="build.dir" value="${basedir}/build"/>
    <property name="jars.dir" value="${basedir}/jars"/>
    <property name="src.dir" value="${basedir}/src"/>
    <property name="bin.dir" value="${basedir}/bin" />   
    <target name="setClassPath">
        <path id="classpath_jars">
            <pathelement path="${basedir}/" />
            <fileset dir="${jars.dir}" includes="*.jar" />
        </path>
        <pathconvert pathsep=":" property="test.classpath" refid="classpath_jars" />
    </target>
    <target name="clean" depends="setClassPath">
        <echo message="deleting existing build directory"/>
        <delete dir="${build.dir}"/>
        <mkdir dir="${build.dir}"/>
    </target>
    <target name="compile" depends="clean">
        <echo message="compiling.........."/>
        <javac destdir="${build.dir}" srcdir="${src.dir}" classpath="${test.classpath}"/>
    </target>
    <target name="runTests" depends="compile">
        <taskdef resource="testngtasks" classpath="${test.classpath}"/>        
        <testng classpath="${test.classpath}:${build.dir}">
            <xmlfileset dir="${basedir}" includes="testng.xml"/>
        </testng>
    </target>    
</project>


How to use ANT tool

1) Write the build.xml inside the project(Only change the project name as your project name)
2) Open cmd and give the path of build.xml
3) Type ant and hit enter.
4) It will create a folder inside project as build 
5) Now run all the test cases and will give the report in cmd screen.

No comments:

Post a Comment

Copyright © 2017 QALEARNINGGUIDE.COM || ALL RIGHTS RESERVED