Skip to main content

Selenium Tutorial: Ant Build for Selenium Java project

Ant is a build tool which could be used to have your tests running either from command line or from Hudson CI tool. There is detailed documentation available for ant here but probably you need to know only a little part of it for you selenium tests. The essentials which are needed to know are:
  1. Project
  2. Target (ant execution point and collection of tasks)
  3. Tasks (could be as simple as compilation)
And there would usually be following targets for Selenium tools -
  1. setClassPath - so that ant knows where you jar files are
  2. loadTestNG - so that you could use testng task in ant and use it to execute testng tests from ant
  3. init - created the build file
  4. clean - delete the build file
  5. compile - compiles the selenium tests
  6. run - executes the selenium tests
Here is my project set up for ant -

And the ant file is -

You may also like to use mail task in your build file so that test report is emailed after test execution. You could find on mail task here


  1. Hi Tarun,

    Your selenium blog is excellent helps a lot. I have a query regarding with ANT and Selenium.Do you any idea how to execute ant selenium framework on different environments. In Maven, i use profiles to build the project on diff environment. Any idea with ANT?..Plz assist me.

  2. Looks like this answers your questions -

  3. I have configured hudson to run my test cases by invoking ant.
    But after my test cases ran successfully, build doesn't stop. I have manually stop the build. Is there a way I can fix this issue?

  4. Not sure if there is an issue with version of ant your are using.
    I suppose you mean to say that target execution never reaches completion, right?
    Could you post your question here -
    with the detail of your build and the target which runs infinitely

    1. Hi

      your blog is very useful for the selenium beginners.

      I initially used ant to run my selenium RC and Webdriver test cases using firefox browser and worked fine. But after firefox version 11 the ant build.xml file is not at all launching the firefox browser. The same problem for chrome browser, it opens the browser but not getting the specified URL and for IE i am getting Eval method not available (issue 217)

      Do you have any suggestion?

  5. Hi,

    Your blog was very much useful for Selenium beginners.

    Initially I used to run my selenium Webdriver and Selenium RC test cases using Ant with firefox browser ( it worked initially well)but now ( after firefox version 11)my ant build.xml file is not at all launching the firefox browser. and if at all i try some times,it fails and i had to restart my machine to run the test in eclipse atleast. The same problem with chrome it opens the browser but not pointing to the mentioned URL and with IE I am getting the error
    Eval method not found. only HtmlUnitDriver works under ant.

    do you have anyy suggestion?
    Thanks in advance.


    1. Could you add more details to your question and post it here -

  6. Q1 How can I run selenium script using ANT on MAC?
    Q2 What all changes I need to do in build.xml file which I have created for windows but needs to run on MAC.


Post a Comment

No spam only genuine comments :)

Popular posts from this blog

Using chrome console to test xPath and css selectors

Note: If you are new to java and selenium then start with selenium java training videos .       Since the advent of selenium there have been many plugin to test xPath / css selectors but you don’t need any of them if you have chrome browser. Using Chrome console you can test both xPath and css selectors. Launch website to be tested in chrome browser and hit F-12 and you would see chrome console opened in lower pane of application - Hit escape key and console would open another pane to write element locators - And now you can start writing xPath or css selectors in chrome console and test them - The syntax for writing css id - $$(“ ”) And hit the enter key. If your expression is right then html snippet of the application element corresponding to the css selector would be displayed - If you mouse over the html snippet in chrome console then it would highlight the corresponding element in application - If you want to clean console of previously wri

Working with URL Redirection with VB Scripts

Had chance to work on checking http status VB script. Looks like not all objects work when used URL redirect, so I used "WinHttp.WinHttpRequest.5.1". Set winhttpreq = CreateObject("WinHttp.WinHttpRequest.5.1") 'Initialize HTTP Request winhttpreq.Open "Get", "" 'Send HTTP Request winhttpreq.Send() Print winhttpreq.StatusText Print winhttpreq.ResponseText for now iteamic website redirects to ciber and this code works perfect for it.

Distributed Load Testing with JMeter

Distributed Testing with JMeter When one JMeter client is not able to offer amount of threads required for load testing then distributed testing is used. In distributed testing - One instance of JMeter client can control number of JMeter instances and collect data from them Test plan does not need to be copied to each server, the client sends it to all servers note - JMeter will run all the threads on all the servers, hence 100 threads on 5 JMeter server would pump 500 threads in total. If many server instances are used, the client JMeter can become overloaded and so the client network connection. This has been improved in latest versions of JMeter by switching to Stripped modes, but you should always check that your client is not overloaded When Client (master) and Server (slave) nodes are on same network (no SSH required) Configure Client Node Herein client is referred as the machine controlling test execution on other JMeter nodes. This is also referred