INTRODUCTION TO ANT
If you are writing Selenium test in Java you need to have a build tool to automate the build process, invoking the test runs and generating the test run reports.
Ant is by far the simplest and the easiest tool to help us achieve that.
In the following blog i have enlisted some features of Ant. You will need to know this to proceed working with Junit and TestNG
* Junit and TestNG integration will be seen in next blog.
ANT Features:
Apache Ant is a Java based Build Tool. It helps in automating the repetative build tasks.It is platform independant and free :)
It has a xml file that is used to control the build process
Ant Install:
- Ant depends on Java, make sure you have java installed on your machine and the JAVA_HOME set. Plus, make sure that the Java bin is set in the PATH env variable.
- Ant can be installed on any OS, make sure you get the right binaries.
- Get on the link http://ant.apache.org.
- Unzip the downloaded file and set the ANT_HOME variable to the directory just before the Bin directory, for example, Unzippped in /scratch/Ant/apache-ant-1.8.4
- Also make sure that the PATH varable has the bin directory set too.
ant -version
This must show the ant version on your box and not error
By now you are set to invoke Ant from command line.
Ant Build file:
Ant's build file is named as build.xml and it must reside in the project base directory [ You are allowed to change this and also change the location of placing this file but make sure that the path it tries to access are relative to it].We have targets in the build.xml that is a collection of tasks
A build file must have a project element and atleast one target element.
Below is an example of a build.xml and the inline comments as to what each lines indicate and the features supported by Ant.
# Project has 3 attributes, do not forget to have the default target defined, name attribute which is the name of the project,
# Default: the target which must be the default one that must be used and the basedirectory as mentioned by user.
# Property sets the env variable, you can use/access these in you test methods
# Once the property is set you can access it using ${} in the any file
# If you have large number of env vars to be set when using any. then use a file to set them. The file must contain a name and value pair
# Above the absoulte path of the property file is not mentioned, hence ant will look in the directory where the build.xml exists.
....
# each target can have 5 attributes, such as
# name: name of the target ; depends: the taget that the present target is dependent on and description: as to what the target does
# if /unless is used to run the target based on the conditions
The site you wann to access is: ${sitename}
....
# Ant provides a set of Data types to be used to perform some set of task in the targets
# In file set you are allowed to pattern match the set of files in a particluar directory OR not select them
# YOu can delete a file or a specific directory as follows:
# Copy files
....
....
ant run : will execute All the suites
This is the summary of what a buil.xml file can be used for.
You can also use Ant to execute Java code, this is very useful in emailing a report, as follows.
public class EmailTestTeam
{
public static void main(String[] args)
{
//.. email code
}
}
}
# In Ant call the class name and that should call your method:

No comments:
Post a Comment