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

Comments

  1. Hi Tarun,

    Your selenium blog is excellent ..it 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.

    ReplyDelete
  2. Looks like this answers your questions -

    http://stackoverflow.com/questions/926238/ant-equivalent-of-maven-profiles

    ReplyDelete
  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?

    ReplyDelete
  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 - http://www.seleniumtests.com/p/testing-forum.html
    with the detail of your build and the target which runs infinitely

    ReplyDelete
    Replies
    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?

      Delete
  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.

    Arun

    ReplyDelete
    Replies
    1. Could you add more details to your question and post it here - http://www.seleniumtests.com/p/selenium-1-forum.html

      Delete
  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.

    ReplyDelete

Post a Comment

No spam only genuine comments :)

Popular posts from this blog

Appium and android mobile app automation

Next appium and Android mobile app automation video tutoria l is live. If you are new to appium then please check - appium-tutorial This video tutorial covers - Start vysor (Just for this session and not mobile automation :)) Start appium and start appium inspector Desired Capabilities platformName - Android deviceName - L2N0219828001013 (as seen on "adb devices") Saved Capability Sets Start Session Scan app elements using appium inspector Get appPackage and appActivity using "APK info" app Install "APK info" app and open app whose appPackage and appActivity are required i.e. calculator Check top section of app icon com.android.calculator2 is app package com.android.calculator2.Calculator is app activity testng.xml file settings for running Android app tests Test details com.seleniumtests.tests.mobile.AndroidAppTest and CalculatorScreen class View beautiful STF test report  

Verify email confirmation using Selenium

Note: If you are new to java and selenium then start with selenium java training videos .     Email confirmation seems to be integral part of any registration process. I came across an application which lets you provide your email address. You can follow the sign up link in you mail and then complete the registration process. Lets consider we provide GMail address for it. Now if were to use only Selenium then we would have to follow following steps - Launch GMail using Selenium; Some how search for new mail in the list of available mails; Some how click on it; Parse the mail message; Get the registration link; Follow up with registration process What do you think of an approach in which you can