{"id":6250,"date":"2020-10-30T16:03:19","date_gmt":"2020-10-30T10:33:19","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=6250"},"modified":"2024-10-18T19:16:51","modified_gmt":"2024-10-18T13:46:51","slug":"apache-ant-with-selenium","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/apache-ant-with-selenium\/","title":{"rendered":"Apache ANT with Selenium"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>What is Apache Ant?<\/strong><\/h2>\n\n\n\n<p>An Ant is an open-source tool that automates the software build process. Apache Ant is a build tool developed using java. It was implemented for the Java project because it has an in-build feature with java but it can be still used for applications built on other languages. Apache Ant is the most popular and conventional build tool. It was provided by Apache Software Foundation and freely distributed under the GNU license. In day to day work schedule, Apache Ant plays an important role in developers as well as Testers environment. It has very immense power to build the code into deployment utilities.<\/p>\n\n\n\n<p>In general, while developing a software product, we need to take care of classpath, cleaning of executable binary files, compiling and execution of source code, creation of reports, etc. If we manually do all these tasks one by one, it will take more time, and the process will lead to errors. To overcome this situation we use a build tool like Ant. It executes and automates all the processes in a sequential order which are mentioned in the Ants configuration file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Benefits of Apache Ant<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ant is implemented and written in Java language thus is a platform-independent build tool. JDK is the only requirement for the tool.<\/li>\n\n\n\n<li>It is Ease to Use\u00a0and offers a wide variety of tasks that fulfil all the requirements of the user.<\/li>\n\n\n\n<li>It creates a complete life cycle i.e compile, clean, executes, report, etc.<\/li>\n\n\n\n<li>End to End application is created, delivered, and deployed.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Features of Apache Ant<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It complies with Java-based applications<\/li>\n\n\n\n<li>Creates zip, jar, war, tar files<\/li>\n\n\n\n<li>Creates Java Doc<\/li>\n\n\n\n<li>It can copy files to different locations<\/li>\n\n\n\n<li>We can move or delete files<\/li>\n\n\n\n<li>It supports TestNG, Junit 4, etc.<\/li>\n\n\n\n<li>It will convert XML based test reports to HTML reports<\/li>\n\n\n\n<li>Emails can be sent to end-users<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to install Ant<\/strong><\/h2>\n\n\n\n<p><strong><em>The entire step by step setup process is as follows<\/em><\/strong><\/p>\n\n\n\n<p><strong>Step 1:<\/strong>&nbsp;Go to&nbsp;<a href=\"http:\/\/ant.apache.org\/bindownload.cgi\" rel=\"nofollow noopener\" target=\"_blank\">http:\/\/ant.apache.org\/bindownload.cgi<\/a>&nbsp;and download the Apache Ant latest version .zip folder (<a href=\"https:\/\/mirrors.estointernet.in\/apache\/ant\/binaries\/apache-ant-1.9.15-bin.zip\" rel=\"nofollow noopener\" target=\"_blank\">apache-ant-1.9.15-bin.zip<\/a>) from the repository.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/-toNcJlNH2PYm3IUpT7slUqEqEUdmJ__D7EaauY3s2bmJ0txvvh7yCoQIFBDmxGCq-xPKuP8gJbRyCKd3_4DxRFoaW9vdMcbp1hXZI4eMVJ8AvUY6UnPL-MECidcUJ5r4NIT1_U\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p><strong>Step 2:<\/strong>&nbsp;Unzip and extract the folder and copy the path to the root of the unzipped folder.<\/p>\n\n\n\n<p>Extract the zipped folder at your desired location onto the local file system.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/CWQ-saEkYOoBUpdunuT80BiIAWqS4zCgaaGqkp4bxOFyXa6vNE4ov6EiQcF-2ejp4HXjOOENI41VE14ex1-LeM9GLKOayImZjW2IOearSpjDzDN8rHNkdZiOVZ6oufEguNunawY\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p><strong>Step 3:<\/strong> Right-click on My Computer&gt;Click Properties&gt;click on&nbsp;<strong>Advanced system settings&gt; <\/strong>Click<strong> on Environment Variables<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/SKRDuCM7uaZXgae3nHWt8SBd5AHA6jhtMHdYVv_aOtHA8cWDswstzS9KF2oxgB7fU1xCt3y_Na_foAErnn7OYPQxnteXjg2LgjW2EOr5_veG_3KrmMtBdjukBdnkBECDnSP4yWg\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p><strong>Step 4: <\/strong>Environment Variable Set Up<\/p>\n\n\n\n<p>Click on&nbsp;<strong>Environment Variables <\/strong>to set up the environment variable<strong>.<\/strong>&nbsp;Click on the New button and enter the Variable name and Variable value as the root path of Ant folder till bin and click OK.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/tL-pvOXzYyoG85P2yEOK43l5R5hDNTk060v_6FwKCdFSEOIEMpvxc5qc_LBoo0nEiZxY_i4bfB3K-ivVPziCN55KIUYeznsWnGLrRuEuIa8XVccpWXXxfLliX-1wRwzQ5F1_uhg\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/Zy8Y7KwXcxINOfiRaMxZUh5otC4mpIuw5qABiImYi5WO9n32ZX4lV1tuhKwKhXcjIknnbPUmXr_jPDv2OiqBi1cXBs6WP1puncj5xkrw_E8ol7ZBmVSM983paeDycAYgTQVI4iY\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p><strong>Step 5:&nbsp;<\/strong> Click on Path at System Variable and click &#8216;Edit&#8217; and append; %ANT_HOME%\\bin.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/Fg4ELXkJVKpdmlxppIbYXo7bNREB88d23C2vgi4RGl5QA7gQ27_eesO7Brf1oMgwU9eYku8m0kiqX6skzdmL2AteF3Ar7j1zL0JfLk8wz8eYkZHi-eQqoOJjZpkPYM3oL8BZAVk\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<p>Restart the system once and now you are ready to use the Ant build tool.<\/p>\n\n\n\n<p><strong>Step 6: <\/strong>Validate Build On Cmd<\/p>\n\n\n\n<p>Open CMD prompt and type command: <strong>ant -version<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Explanation of Build.xml<\/strong><\/h3>\n\n\n\n<p>Let&#8217;s understand the code within a sample build.XML<\/p>\n\n\n\n<p><strong>Sample Build.Xml<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?>\n&lt;project name=\"Selenium_Testing\" default=\"dist\" basedir=\".\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;property name=\"src\" value=\".\/src\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;property name=\"lib\" value=\".\/lib\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;property name=\"bin\" value=\".\/bin\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;property name=\"report\" value=\".\/report\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;property name=\"test.dir\" value=\".\/src\/com\/tests\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;path id=\"Selenium_Testing.classpath\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"${bin}\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;fileset dir=\"${lib}\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;include name=\"**\/*.jar\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/fileset>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/path>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;echo message=\"--------------------Selenium Testing Programs----------------------\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;target name=\"init\" description=\"Delete the binary folder and create it again\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;echo message=\"----------Delete the binary folder and create it again----------\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;delete dir=\"${bin}\" \/>\n&lt;!-- Create the build directory structure used by compile -->\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;mkdir dir=\"${bin}\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/target>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;target name=\"compile\" depends=\"init\" description=\u201d Source files compilation\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;echo message=\"---------- source files compilation----------\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;javac source=\"1.8\" srcdir=\"${src}\" fork=\"true\" destdir=\"${bin}\" includeantruntime=\"false\" debug=\"true\" debuglevel=\"lines,vars,source\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;classpath refid=\"Learning_Selenium.classpath\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/javac>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/target>\n&lt;!--mkdir tag will create new director-->\n&lt;mkdir dir=\"${build.dir}\"\/>\n&lt;echo message=\"classpath:${test.classpath}\"\/>\n&lt;echo message=\"compiling..........\"\/>\n&lt;!--javac tag used to compile java program code and move .class files to a new folder-->\n&lt;javac destdir=\"${build.dir}\" srcdir=\"${src.dir}\">\n&lt;classpath refid=\"classpath_jars\"\/>\n&lt;\/javac>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;target name=\"exec\" depends=\"compile\" description=\"Launch the test suite\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;echo message=\"----------Launch the test suite----------\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;delete dir=\"${report}\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;mkdir dir=\"${report}\" \/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;mkdir dir=\"${report}\/xml\" \/>\n&lt;target name=\"run\" depends=\"compile\">\n&lt;!--java tag will execute main function from the jar created in compile target section-->\n&lt;java jar=\"${selenium.dir}\/Selenium.jar\"fork=\"true\"\/>\n&lt;\/target>\n&lt;\/project><\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>The Project element consists of the project name and basedir attribute.<\/p>\n\n\n\n<p><strong>&lt;project&nbsp;name=\u201cSelenium_Testing\u201d basedir=\u201c.\u201d&gt;<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Name<\/strong>\u00a0\u2013 The name attribute signifies the name of the project. Here in our case, the project\u2019s name is \u201cSelenium_Testing\u201d.<\/li>\n\n\n\n<li><strong>Basedir<\/strong>\u00a0\u2013 The Basedir attribute represents the root directory or base directory of an application. Under this directory, there may be several other folders like src, lib, bin, etc.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In the build.XML file, Property tags are used as variables<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;property name=\"build.dir\" value=\"${basedir}\/build\"\/&gt;\n\t\t&lt;property name=\"external.jars\" value=\".\\resources\"\/&gt;\n\t&lt;property name=\"selenium.dir\" value=\"${external.jars}\/Selenium\"\/&gt;\n&lt;property name=\"src.dir\"value=\"${basedir}\/src\"\/&gt;\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Target tags will execute in sequential order. The name attribute is the name of the target. In a single build.xml, we can have multiple targets<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;target name=\"setClassPath\"&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>pathelement tag will set the path to the common location root where all files are stored<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code> &lt;pathelement path=\"${basedir}\/\"\/&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>path tag will bundle all the files<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;path id=\"classpath_jars\"&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>fileset tag will set classpath for third party jar in your project<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code> &lt;fileset dir=\"${selenium.dir}\" includes=\"*.jar\"\/&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Echo tag is used to print text on the console<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;echo message=\"deleting current build directory\"\/&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Delete tag will clear all the data from the given folder<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;delete dir=\"${build.dir}\"\/&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>mkdir tag is used to create a new directory<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;mkdir dir=\"${build.dir}\"\/&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>javac tag is used to compile java program and move .class files to a new folder<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;javac destdir=\"${build.dir}\" srcdir=\"${src.dir}\"&gt;\n\t&lt;classpath refid=\"classpath_jars\"\/&gt;\n&lt;\/javac&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>jar tag will create jar file from .class files<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;jar destfile=\"${selenium.dir}\/Selenium.jar\" basedir=\"${build.dir}\"&gt;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&#8216;depends&#8217; attribute is used to depend one target on another target<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;target name=\"exex\" depends=\"compile\"&gt;<\/code><\/pre>\n\n\n\n<p>In the Ant build file, all the tasks are defined under Target elements and it corresponds to a particular task or a goal.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;target name=\u201cinit\u201d description=\u201cDelete the binary folder and create it again\u201d&gt;\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Following goals are created in the above XML code,&nbsp;<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Deleting and creating directories<\/li>\n\n\n\n<li>Code compilation<\/li>\n\n\n\n<li>Test classes execution<\/li>\n\n\n\n<li>Test reports generation<\/li>\n<\/ol>\n\n\n\n<p><em>&lt;target<\/em>&nbsp;<em>name=\u201cexec\u201d<\/em>&nbsp;<em>depends=\u201ccompile\u201d<\/em>&nbsp;<em>description=\u201cTest suite launch\u201d&gt;<\/em><\/p>\n\n\n\n<p>The &#8216;depends&#8217; attribute is used to depend on one target on another target.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Run Ant using Eclipse plugin<\/strong><\/h2>\n\n\n\n<p>Right-click on build.xml file -&gt;Click on Run as -&gt; Click on Build file<\/p>\n\n\n\n<p><strong><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/6l1MJX0PRL_LoswooI7HeYle8UPcOSYg0UHXPx1r_nrdcYp664jSCBu6ij0RzrJKVa8jk810hCPT99-Xk68mEyokMRCRRN1FkVmdOpzkcftBFqyBQaWF1Y5Q0ud-etmJz5bRgL8\" width=\"602\" height=\"265\" alt=\"\" title=\"\"><\/strong><\/p>\n\n\n\n<p>After completion of execution, Ant generates a test execution report inside the \u201cReport\u201d folder.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Executing Selenium Web Driver Scripts using ANT&nbsp;<\/strong><\/h2>\n\n\n\n<p><strong>Step1:<\/strong> Launch the <a href=\"https:\/\/www.h2kinfosys.com\/blog\/selenium-jars-download-configure-eclipse\/\">eclipse <\/a>and create a new Java Project<\/p>\n\n\n\n<p><strong>Step2:<\/strong> Create a Class name as \u201cGoogleSearch\u201c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong> Ant;\n<strong>import<\/strong> org.openqa.selenium.WebDriver;\n<strong>import<\/strong> org.openqa.selenium.WebElement;\n<strong>import<\/strong> org.openqa.selenium.firefox.FirefoxDriver;\n<strong>import<\/strong> org.openqa.selenium.By;\n<strong>import<\/strong> org.openqa.selenium.support.ui.ExpectedCondition;\n<strong>import<\/strong> org.openqa.selenium.support.ui.WebDriverWait;\n<strong>import<\/strong> org.junit.*;\n<strong>import<\/strong> <strong>static<\/strong> org.junit.Assert.*;\n<strong>public<\/strong> <strong>class<\/strong> GoogleSearch {\n<strong>private<\/strong> WebDriver driver;\n@Before\n<strong>public<\/strong> <strong>void<\/strong> setUp() {\n\/\/ Launch a new Firefox instance\nSystem.<em>setProperty<\/em>(\"webdriver.chrome.driver\", \"F:\\\\drivers\\\\chromedriver.exe\");\n\/\/create chrome instance\ndriver = <strong>new<\/strong> ChromeDriver();\/\/ Maximize the browser window\ndriver.manage().window().maximize();\n\/\/ Navigate to Google\ndriver.get(\"http:\/\/www.google.com\");\n}\n@Test\n<strong>public<\/strong> <strong>void<\/strong> GoogleSearch() {\n\/\/ Using the name find the Search Box Text input element\nWebElement element = driver.findElement(By.name(\"q\"));\n\/\/ Clear the existing text value\nelement.clear();\n\/\/ Enter the Search Keyword\nelement.sendKeys(\"Software Testing Tutorials\");\n\/\/ Submit the Search Query\nelement.submit();\n\/\/ Timeout after 10 seconds and wait for the page to get rendered\n<strong>new<\/strong> WebDriverWait(driver,10).until(<strong>new<\/strong>\nExpectedCondition&lt;Boolean>() {\n<strong>public<\/strong> Boolean apply(WebDriver d) {\n<strong>return<\/strong> d.getTitle()\n.startsWith(\"Software Testing Tutorials\");\n}\n});\nassertEquals(\"Software Testing Tutorials - Google Search\",driver.getTitle());\n}\n@After\n<strong>public<\/strong> <strong>void<\/strong> tearDown() <strong>throws<\/strong> Exception {\n\/\/ Close the browser\ndriver.quit();\n}\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Execute TestNG Tests from ANT build.xml<\/strong><\/h2>\n\n\n\n<p>Let us create a sample project and execute TestNG tests using ANT build.xml. First we will create a project with some sample testng tests before creating build.xml file.<\/p>\n\n\n\n<p><strong>Step 1:<\/strong> Create a project<\/p>\n\n\n\n<p><strong>Step 2:<\/strong> Create a sample packages as &#8216;com.packge.one&#8217; and &#8216;com.packge.two&#8217;<\/p>\n\n\n\n<p><strong>Step 3:<\/strong> Create multiple classes with in packages &#8216;TestOne&#8217; under &#8216;com.packge.one&#8217; and &#8216;TestTwo&#8217; under &#8216;com.packge.two&#8217;<\/p>\n\n\n\n<p>Create class &#8216;TestOne&#8217; under &#8216;com.packge.one&#8217;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>package<\/strong> com.packge.one;\n\n<strong>import<\/strong> org.testng.annotations.AfterClass;\n<strong>import<\/strong> org.testng.annotations.BeforeClass;\n<strong>import<\/strong> org.testng.annotations.Test;\n\n<strong>public<\/strong> <strong>class<\/strong> TestOne {\n@BeforeClass\n<strong>public<\/strong> <strong>void<\/strong> setUp() {\nSystem.<strong><em>out<\/em><\/strong>.println(\"*** In class - Test A ***\");\n}\n\n@Test\n<strong>public<\/strong> <strong>void<\/strong> testOne() {\nSystem.<strong><em>out<\/em><\/strong>.println(\"hello\");\n}\n\n@Test\n<strong>public<\/strong> <strong>void<\/strong> testTwo() {\nSystem.<strong><em>out<\/em><\/strong>.println(\"hello\");\n}\n\n@AfterClass\n<strong>public<\/strong> <strong>void<\/strong> tearDown() {\nSystem.<strong><em>out<\/em><\/strong>.println(\"*** End of class***\");\n}\n}\n\u00a0\n\u00a0\nCreate class 'TestTwo' under 'com.packge.two'\n<strong>package<\/strong> com.packge.two;\n\n<strong>import<\/strong> org.testng.annotations.AfterClass;\n<strong>import<\/strong> org.testng.annotations.BeforeClass;\n<strong>import<\/strong> org.testng.annotations.Test;\n\n<strong>public<\/strong> <strong>class<\/strong> TestTwo {\n@BeforeClass\n<strong>public<\/strong> <strong>void<\/strong> setUp() {\nSystem.<strong><em>out<\/em><\/strong>.println(\"*** In class - Test B ***\");\n}\n\n@Test\n<strong>public<\/strong> <strong>void<\/strong> testOne() {\nSystem.<strong><em>out<\/em><\/strong>.println(\"hello\");\n}\n\n@Test\n<strong>public<\/strong> <strong>void<\/strong> testTwo() {\nSystem.<strong><em>out<\/em><\/strong>.println(\"hello\");\n}\n\n@AfterClass\n<strong>public<\/strong> <strong>void<\/strong> tearDown() {\nSystem.<strong><em>out<\/em><\/strong>.println(\"*** End of class***\");\n}\n\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Step 4:<\/strong> Create testng.xml file and add the classes to test<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE suite SYSTEM \"http:\/\/testng.org\/testng-1.0.dtd\">\n&lt;suite name=<em>\"Sample Test Suite\"<\/em>>\n\u00a0\u00a0&lt;test name=<em>\"Sample Test\"<\/em>>\n\u00a0\u00a0\u00a0\u00a0&lt;classes>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;class name=<em>\"com.packge.one.TestOne\"<\/em>\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;class name=<em>\"com.packge.two.TestTwo\"<\/em>\/>\n\u00a0\u00a0\u00a0\u00a0&lt;\/classes>\n\u00a0\u00a0&lt;\/test>\n&lt;\/suite><\/code><\/pre>\n\n\n\n<p>To create build.xml file, Right click on the project -&gt; New -&gt; File -&gt; Enter the file name and Click on the Finish button.<\/p>\n\n\n\n<p>Below is the build.xml file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n&lt;!-- WARNING: Eclipse auto-generated file.\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Any modifications will be overwritten.\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0To include a user specific buildfile here, simply create one in the same\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0directory with the processing instruction &lt;?eclipse.ant.import?>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0as the first entry and export the buildfile again. -->&lt;project basedir=\".\" default=\"build\" name=\"AntTestNG\">\n\u00a0\u00a0\u00a0\u00a0&lt;property environment=\"env\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;property name=\"ECLIPSE_HOME\" value=\"..\/..\/eclipse\/jee-2020-092\/eclipse\/\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;property name=\"debuglevel\" value=\"source,lines,vars\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;property name=\"target\" value=\"11\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;property name=\"source\" value=\"11\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;path id=\"TestNG.libraryclasspath\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"..\/..\/.p2\/pool\/plugins\/org.testng_7.3.0.r202008060316.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"..\/..\/.p2\/pool\/plugins\/com.beust.jcommander_1.78.0.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"..\/..\/.p2\/pool\/plugins\/org.apache-extras.beanshell.bsh_2.0.0.b6.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"..\/..\/.p2\/pool\/plugins\/org.yaml.snakeyaml_1.21.0.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;\/path>\n\u00a0\u00a0\u00a0\u00a0&lt;path id=\"AntTestNG.classpath\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"bin\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"..\/..\/Downloads\/selenium-java-3.141.59\/client-combined-3.141.59.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"..\/..\/Downloads\/selenium-java-3.141.59\/client-combined-3.141.59-sources.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"..\/..\/Downloads\/selenium-java-3.141.59\/libs\/byte-buddy-1.8.15.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"..\/..\/Downloads\/selenium-java-3.141.59\/libs\/commons-exec-1.3.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"..\/..\/Downloads\/selenium-java-3.141.59\/libs\/guava-25.0-jre.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"..\/..\/Downloads\/selenium-java-3.141.59\/libs\/okhttp-3.11.0.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;pathelement location=\"..\/..\/Downloads\/selenium-java-3.141.59\/libs\/okio-1.14.0.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;path refid=\"TestNG.libraryclasspath\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;\/path>\n\u00a0\u00a0\u00a0\u00a0&lt;target name=\"init\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;mkdir dir=\"bin\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;copy includeemptydirs=\"false\" todir=\"bin\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;fileset dir=\"src\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;exclude name=\"**\/*.launch\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;exclude name=\"**\/*.java\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/fileset>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/copy>\n\u00a0\u00a0\u00a0\u00a0&lt;\/target>\n\u00a0\u00a0\u00a0\u00a0&lt;target name=\"clean\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;delete dir=\"bin\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;\/target>\n\u00a0\u00a0\u00a0\u00a0&lt;target depends=\"clean\" name=\"cleanall\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;target depends=\"build-subprojects,build-project\" name=\"build\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;target name=\"build-subprojects\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;target depends=\"init\" name=\"build-project\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;echo message=\"${ant.project.name}: ${ant.file}\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;javac debug=\"true\" debuglevel=\"${debuglevel}\" destdir=\"bin\" includeantruntime=\"false\" source=\"${source}\" target=\"${target}\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;src path=\"src\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;classpath refid=\"AntTestNG.classpath\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/javac>\n\u00a0\u00a0\u00a0\u00a0&lt;\/target>\n\u00a0\u00a0\u00a0\u00a0&lt;target description=\"Build all projects which reference this project. Useful to propagate changes.\" name=\"build-refprojects\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;target description=\"copy Eclipse compiler jars to ant lib directory\" name=\"init-eclipse-compiler\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;copy todir=\"${ant.library.dir}\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;fileset dir=\"${ECLIPSE_HOME}\/plugins\" includes=\"org.eclipse.jdt.core_*.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/copy>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;unzip dest=\"${ant.library.dir}\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;patternset includes=\"jdtCompilerAdapter.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;fileset dir=\"${ECLIPSE_HOME}\/plugins\" includes=\"org.eclipse.jdt.core_*.jar\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;\/unzip>\n\u00a0\u00a0\u00a0\u00a0&lt;\/target>\n\u00a0\u00a0\u00a0\u00a0&lt;target description=\"compile project with Eclipse compiler\" name=\"build-eclipse-compiler\">\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;property name=\"build.compiler\" value=\"org.eclipse.jdt.core.JDTCompilerAdapter\"\/>\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&lt;antcall target=\"build\"\/>\n\u00a0\u00a0\u00a0\u00a0&lt;\/target>\n&lt;\/project><\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Click on File -&gt; click on Export -&gt; General -&gt; Ant Buildfiles and specify the file name, project, etc.<\/p>\n\n\n\n<p>Right-click on Ant build from Eclipse and select Ant Build, you should see a message as &#8221;BUILD SUCCESSFUL&#8221; as below:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/oCCEhbWQGJzr5yl8RaB8hpj75uk72Kq-7YkUPy8lXsi2VZRO_ogvp8TdFS5XvNOWg0w8VNe--QA7DieW8UvPx63XoG6qyvAqqvPZgrlqRJNiovS08YGQO8CqC3vwtbyWgOfEyuY\" alt=\"\" title=\"\"><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><strong>:<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>An Ant is an open-source tool that automates the software build process\u00a0<\/li>\n\n\n\n<li>Apache Ant is a build tool developed using java.<\/li>\n\n\n\n<li>Ant is used for compiling and execution of source code, creation of reports, etc.<\/li>\n\n\n\n<li>Build.xml file is used to configure execution targets using Ant.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>What is Apache Ant? An Ant is an open-source tool that automates the software build process. Apache Ant is a build tool developed using java. It was implemented for the Java project because it has an in-build feature with java but it can be still used for applications built on other languages. Apache Ant is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6838,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[1942,1943,45],"class_list":["post-6250","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-selenium-tutorials","tag-apache-ant","tag-apache-ant-with-selenium","tag-selenium"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/6250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=6250"}],"version-history":[{"count":0,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/6250\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/6838"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=6250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=6250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=6250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}