Apache Ant is an open source build tool. A build tool can be used to compile the source code, creating the build artifacts such as JAR, WAR, and EAR files. Some of the other usage of ANT is to run unit tests, do the application deployment on containers such as JBoss, Tomcat, WebSphere, WebLogic, GlassFish, etc, and to run Automated Selenium Tests.
In this example, we will demonstrate how to Generate HTML Reports using ANT. Let's follow the given steps:
Step 1: Download Apache Ant
Download Apache Ant
OS | Archive name |
---|---|
Windows | apache-ant-1.8.4-bin.zip |
Linux | apache-ant-1.8.4-bin.tar.gz |
Mac | apache-ant-1.8.4-bin.tar.gz |
Set the ANT_HOME environment variable to point to the base directory location where ANT libraries is stored on your machine. For example, We've stored Ant libraries in apache-ant-1.8.4 folder on various Operating Systems as follows.
OS | Output |
---|---|
Windows | Set the environment variable ANT_HOME to C:\Program Files\Apache Software Foundation\apache-ant-1.8.4 |
Linux | export ANT_HOME=/usr/local/\apache-ant-1.8.4 |
Mac | export ANT_HOME=/Library/\apache-ant-1.8.4 |
Append Ant compiler location to System Path is as follows for different OS:
OS | Output |
---|---|
Windows | Append the string ;%ANT_HOME\bin to the end of the system variable, Path. |
Linux | export PATH=$PATH:$ANT_HOME/bin/ |
Mac | not required |
Download JUnit Archive
OS | Archive name |
---|---|
Windows | junit4.10.jar |
Linux | junit4.10.jar |
Mac | junit4.10.jar |
Let us create a new project in Eclipse and write a build.xml file to execute the Java files in this project
1) Create a new project – JavaProject
2) Create a new package (under src) – seleniumtest
3) Under this package, create new Java class – AntTest.java
4) Record a Selenium Test and export in JUnit 4 format as below
package seleniumtest;
import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;
public class AntTest extends SeleneseTestCase{
private static SeleniumServer seleniumServer;
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://www.google.co.in/");
seleniumServer = new SeleniumServer();
seleniumServer.start();
selenium.start();
}
@Test
public void testGoogleSearch() throws Exception {
selenium.open("/");
selenium.click("link=Advanced search");
selenium.waitForPageToLoad("30000");
selenium.type("as_q", "selftechy, selenium");
selenium.click("//input[@value='Advanced Search']");
selenium.waitForPageToLoad("30000");
}
@After
public void tearDown() throws Exception {
selenium.stop();
seleniumServer.stop();
}
}
Create ANT Build.xml under JavaProject
<?xml version="1.0" encoding="UTF-8"?>
<project name="test" default="exec" basedir=".">
<property name="src" value="./src" />
<property name="lib" value="./lib" />
<property name="bin" value="./bin" />
<property name="report" value="./report" />
<path id="test.classpath">
<pathelement location="${bin}" />
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="init">
<delete dir="${bin}" />
<mkdir dir="${bin}" />
</target>
<target name="compile" depends="init">
<javac source="1.6" srcdir="${src}" fork="true" destdir="${bin}" includeantruntime="false">
<classpath>
<pathelement path="${bin}">
</pathelement>
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>
<target name="exec" depends="compile">
<delete dir="${report}" />
<mkdir dir="${report}" />
<mkdir dir="${report}/xml" />
<junit printsummary="yes" haltonfailure="no">
<classpath>
<pathelement location="${bin}" />
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
</classpath>
<test name="seleniumtest.AntTest" haltonfailure="no" todir="${report}/xml" outfile="TEST-result">
<formatter type="xml" />
</test>
</junit>
<junitreport todir="${report}">
<fileset dir="${report}/xml">
<include name="TEST*.xml" />
</fileset>
<report format="frames" todir="${report}/html" />
</junitreport>
</target>
</project>
Run the following ant command
C:\WORKSPACE\JavaProject\ant
Hi,
ReplyDeleteNice blog. I have question when I run ANT and generate Junit reports
I see that the package name is shown as "None" and the class name is shown as Blank. Can you let me know as to what the issue is.
Regards
Prashanth
Please help, How I can send the Selenium test report automatically through build.xml
ReplyDeleteHi, I have follow u r step but it create XML file rather than HTML
ReplyDeletepls provide me a steps to generate report in html format
Hi..
ReplyDeleteI have created the code given above but i don't know, how to run the ANT command..?
Can anyone help me on this..
"E:\HLUII-Testing\JavaProject" this was my workspace.. here there was no files related to ANT.
Hi prasanth,
ReplyDeletecan you please tell me how to download the files in any UI using Firefox profiles with set preference without using AutoIT and any other tools.
شركة تسليك مجاري المطبخ بالرياض
ReplyDeleteشركة تسليك مجاري بالرياض
شركة تسليك مجارى الحمام بالرياض
level تسليك المجاري بالرياض
افضل شركة تنظيف بالرياض
تنظيف شقق بالرياض
شركة تنظيف منازل بالرياض
شركة غسيل خزنات بالرياض
افضل شركة مكافحة حشرات بالرياض
رش مبيدات بالرياض
شركة تخزين عفش بالرياض
شركة تنظيف مجالس بالرياض
تنظيف فلل بالرياض
ابى شركة تنظيف بالرياض
I love the podcasts available on this site.
ReplyDeleteflooring
ReplyDeleteBest South Delhi SchoolsAt Apeejay School International , the Best IB Schools in Delhi where these skills not only help students navigate academic subjects effectively but also prepare them to succeed in their future careers and daily lives. The International Baccalaureate (IB) framework, known for its rigorous and comprehensive approach to education, provides an ideal foundation for fostering these skills.
ReplyDeleteThought-provoking post. There’s an education center I truly admire for its consistent focus on quality. Every child gets the attention they need to thrive. With such dedication to student success, it’s often called the Best school in jaipur by those who know it well.
ReplyDeleteThe post was informative, and I’d like to tell about the Best School in Thanefocused on developing academic excellence with equal emphasis on co-curricular and sports activities.
ReplyDeleteThe details provided were thorough. I would like to tell you about a school that prioritizes student well-being alongside academic success. Its balanced approach makes it the best school in panvel.
ReplyDeleteLooking beyond rote learning, I found a school in Jaipur that fosters independent thinking, collaboration, and innovation—undoubtedly one of the Best schools in jaipur
ReplyDeleteGreat post with valuable insights! I want to share that St. Wilfred’s truly stands out for its holistic approach to learning. The focus on academics, arts, and overall development makes it one of the Best School in Navi Mumbai. The nurturing environment and skilled teachers really set it apart. Keep up the great work!
ReplyDeleteI really liked this post; the points shared are insightful and well-presented. I want to share that schools play such a vital role in shaping a child’s future, and St. Wilfred’s commitment to academics, extracurriculars, and overall development truly stands out. No wonder it’s often regarded as the Best School in Thane for its holistic approach to education.
ReplyDeleteIt was a great post—really good content! I wanted to share how impressed I am with the focus on holistic learning and values. St. Wilfred’s truly reflects what parents seek when looking for the Best School in Jaipur. The facilities, leadership vision, and student activities like the Spell Bee show real commitment to growth. Keep up the great work—would love to see more student stories on the site!
ReplyDelete