Selenium – Use Ant to Generate HTML Reports

by seetaram on June 29, 2011

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.

Ant is a powerful build tool and also is very much extensible.  There are several open source Ant libraries available which need to be just downloaded, unzipped, and copied (JAR file) into the Ant’s “lib” folder.  Once the library file is copied, then we can utilize the “Tasks” in the Ant’s build.xml file.  Ant’s “contrib library, jsch library, etc” are the best examples for such libraries.

Let us create a new project in Eclipse and write a build.xml file to execute the Java files in this project (For details on how to setup Eclipse, please visit How to Setup Eclipse for Selenium Test Automation):

  1. Create a new project – SampleTests
  2. Create a new package (under src) – com.selftechy.seltests
  3. Under this package, create new Java class – SeleniumTest.java
  4. Record a Selenium Test and export in JUnit 4 format as below
package com.selftechy.seltests;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;

public class SeleniumTest 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();
	}

}

Let us try to create a build.xml file for execution of this Java class using Ant:

<?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}" >
			<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="com.selftechy.seltests.SeleniumTest" 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>

Looking at the above build.xml file makes you feel it is very much complex but that is not the case if it is understood properly.

Let us try to explore all the XML tags and attributes of the build.xml file.

basedir – value of this is “.” (just a dot or period) that is the path of the build.xml file.  i.e. In this example I have kept the build.xml file in the path – F:\Helios-Workspace\SelfTechy\SampleTests

default – “exec” – this refers to the default ant target which will be executed when there is no ant target is mentioned while executing the ant command in the command prompt. For example we can just say “ant” in the command prompt without specifying the target as argument.  If we need to execute a specific target then we can specify the target as “ant compile or ant init or ant run”, etc.

One more thing I want to clarify is “./”, this refers to the current working directory.  If you want to refer to any of the parent folder then use “../” in any of the ant targets.

Each <target> will have different ant tasks such as javac, mkdir, delete, junit, etc.  These are actually the actions performed on the Java code provided in the folders.

The Ant targets written in this build.xml file are exec, compile, and init.  In each of the <target> we have specified “depends” attribute which says Ant to execute the target specified first and then the current target.  Hence, Ant will be executing the different targets in a sequential manner.

init – This Ant target first deletes the bin folder and then recreates it.

compile – This Ant target compiles the java code in the src folder and then puts the binary (class) files in the bin folder.

exec – this executes the class files in the bin folder and then generates report folder and copies all the HTML / XML files into this folder.

Install and configure JDK and ANT

Before doing above all ANT and JDK has to be downloaded and installed on the system.

Download JDK from – JDK download link

Download ANT from Apache web site – ANT download link

Unzip the ant and copy to C:\Ant folder

Now we need to configure environment variables: ANT_HOME and JAVA_HOME

Copy the path to both Ant’s bin folder and JDK’s bin folder should be (C:\Ant\bin and C:\program files\Java\JDK\bin) copied to “path” environment variable.  System has to be restarted once after the environment variables are set.

Execute JUnit test from Ant and generate HTML reports

Go to command prompt – > navigate to folder where the build.xml is kept (F:\Helios-Workspace\SelfTechy\SampleTests) and then execute the following command:

F:\Helios-Workspace\SelfTechy\SampleTests>ant (press enter)

This should fire the Selenium tests and generate the HTML / XML reports and put them into the report folder.

After the execution, it creates one more folder – > report and it contains HTML reports that should look as below:

JUnitReport

{ 57 comments… read them below or add one }

Bretick September 6, 2011 at 10:17 am

Hello,
I wonder if there is way how to achieve by JUnit or TestNG the report like for example this:
http://oshyn.com/blogResources/belenPadillaPosts/3_selenium_testsuite_results.jpg
Is this possible please?

I would like to prepare test suites by JUnit or TestNG and execute them by Hudson CI and then obtain html report like above 3_selenium_testsuite_results.jpg…

Reply

seetaram September 7, 2011 at 9:32 am

Yes. that is possible…follow the below steps:

1. configure TestNg & ReportNG plugin
2. Run the test suite from the Ant / maven
3. If it is JUnit then Hudson has some configuration options and if it is TestNG then there is a TestNG plugin that you need to configure in Hudson
4. Create a new Job in Hudson and configure Junit results / TestNG plugin
5. Execute the Job from Hudson.

You can see the results in Hudson Dashboard. I think you need to know Ant / Maven and XML. Otherwise, it is little bit difficult to understand.

Reply

jayaram prasad September 19, 2012 at 8:44 am

Thank you sitaram…..

it was very usefule

Jai.

Reply

Bretick October 27, 2011 at 8:29 pm

Hello again,
I can configure everything you’ve described above and it works fine, I can generate TestNG default report, I can generate ReportNG report, too. But I’m looking for a solution with TestNG which generates reports where are hightlighted selenium commands (PASS/FAIL) like the attached example 3_selenium_testsuite_results.jpg… In my opinion TestNG default report or ReportNG report doesn’t get me as friendly report as mentioned example. What do you think about it?

Reply

seetaram October 28, 2011 at 5:05 am

I agree with you, TestNG generates the reports TestSuite level / Tests level but not at the Selenese commands level. So, we get results for TestSuite as well as Test methods. Whatever you have given the example report that is actually ran by Selenium htmlSuite runner.

But having said that we can always write our own Java code to make any enhancements needed in the framework.

Reply

Peter Harris November 2, 2011 at 1:07 pm

Hi Seetaram,

I have reviewed a number websites where build.xml to is used to generate the Junit reports using selenium, and this is the only one I can get to work. However the above build.xml works with a single test case only. How could it be updated to process multiple tests?

Thanks, Peter

Reply

seetaram November 3, 2011 at 3:58 am

Hi Peter,

“com.selftechy.seltests.SeleniumTest”

The above can also be used for multiple tests. If the class “SeleniumTest” contains multiple test methods, then it executes multiple tests. In the above example, the class contains only one test, hence it executes only one. You can also have multiple test classes running with Test Suites.

Thanks,
Seetaram

Reply

Peter Harris November 3, 2011 at 2:34 pm

Thanks for the reply. Fair enough, but then the junit report will only ever have 1 entry. i.e. that for SeleniumTest.

By the way have you ever come across the problem whereby ‘ant’ is run, a browser is opened and then just hangs, stating ‘connecting to localhost …’ . I’m currently getting this every time I run ant.

Reply

Ajith June 9, 2012 at 7:55 am

@Peter,
I think u need to check whether u have started the selenium server in another terminal(command prompt)window…here how it goes..
1. open another terminal window other than the one used to run ant
2. then in terminal window set the path for selenium-server.jar file till where it is stored
3. then type this command —> java -jar selenium-server.jar and enter to start the server in back end and leave it alone.
4. then finally run ant in your terminal as usual.

Hope this can solve your issue else atleast useful for others having above issue..

Reply

babu November 28, 2011 at 6:37 am

Hi seetram.,
Cau u sugesst how to generate xml file to generate the reports

regards.,
Babu.m

Reply

seetaram November 28, 2011 at 12:28 pm

@babu

Create Report in XML format. For this you need to know how to create a file in XML format.

Reply

david December 14, 2011 at 2:47 am

Hi seetaram,
I’ve been trying to generate a report for my tests using eclipse but I can only generate the build.xml like this: https://gist.github.com/1475016 why don’t the report appear? please help.. I’m so confused.

Reply

seetaram December 14, 2011 at 12:21 pm

Give me some more information on how do you generate build.xml file

Reply

guru March 13, 2012 at 9:07 am

Hi Respected seetaram
i am facing the following error at class line, after the setup statement and in test where i used selenium.xxx all lines
“The field SeleneseTestCase.selenium is deprecated”
how can i over come it?

Regards

Reply

seetaram March 24, 2012 at 9:31 am

deprecated.. means that function / method is not available in the current version.. need not to panic still you can go ahead and use the method…

Reply

guru March 13, 2012 at 9:36 am

Hi Respected Seetaram,

I am facing the following error when i executed using ant, can you help me to solve this problem pls….

C:\WorkSpace4Se\SampleTests>ant
Buildfile: C:\WorkSpace4Se\SampleTests\build.xml

init:
[delete] Deleting directory C:\WorkSpace4Se\SampleTests\bin
[mkdir] Created dir: C:\WorkSpace4Se\SampleTests\bin

compile:
[javac] C:\WorkSpace4Se\SampleTests\build.xml:21: warning: ‘includeantruntim
e’ was not set, defaulting to build.sysclasspath=last; set to false for repeatab
le builds
[javac] Compiling 1 source file to C:\WorkSpace4Se\SampleTests\bin
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:3: package com.thoughtworks.selenium does not exist
[javac] import com.thoughtworks.selenium.*;
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:4: package org.junit does not exist
[javac] import org.junit.*;
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:5: package org.openqa.selenium.server does not exist
[javac] import org.openqa.selenium.server.SeleniumServer;
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:7: cannot find symbol
[javac] symbol: class SeleneseTestCase
[javac] public class SeleniumTest extends SeleneseTestCase{
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:8: cannot find symbol
[javac] symbol : class SeleniumServer
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] private static SeleniumServer seleniumServer;
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:9: cannot find symbol
[javac] symbol : class Before
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] @Before
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:18: cannot find symbol
[javac] symbol : class Test
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] @Test
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:28: cannot find symbol
[javac] symbol : class After
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] @After
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:11: cannot find symbol
[javac] symbol : class Selenium
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] Selenium selenium2 = selenium;
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:11: cannot find symbol
[javac] symbol : variable selenium
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] Selenium selenium2 = selenium;
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:12: cannot find symbol
[javac] symbol : variable selenium
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] selenium = new DefaultSelenium(“localhost”, 4444, “*chro
me”, “http://www.google.co.in/”);
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:12: cannot find symbol
[javac] symbol : class DefaultSelenium
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] selenium = new DefaultSelenium(“localhost”, 4444, “*chro
me”, “http://www.google.co.in/”);
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:13: cannot find symbol
[javac] symbol : class SeleniumServer
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] seleniumServer = new SeleniumServer();
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:15: cannot find symbol
[javac] symbol : variable selenium
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] selenium.start();
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:20: cannot find symbol
[javac] symbol : variable selenium
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] selenium.open(“/”);
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:21: cannot find symbol
[javac] symbol : variable selenium
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] selenium.click(“link=Advanced search”);
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:22: cannot find symbol
[javac] symbol : variable selenium
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] selenium.waitForPageToLoad(“30000″);
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:23: cannot find symbol
[javac] symbol : variable selenium
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] selenium.type(“as_q”, “selftechy, selenium”);
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:24: cannot find symbol
[javac] symbol : variable selenium
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] selenium.click(“//input[@value='Advanced Search']“);
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:25: cannot find symbol
[javac] symbol : variable selenium
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] selenium.waitForPageToLoad(“30000″);
[javac] ^
[javac] C:\WorkSpace4Se\SampleTests\src\com\selftechy\seltests\SeleniumTest.
java:30: cannot find symbol
[javac] symbol : variable selenium
[javac] location: class com.selftechy.seltests.SeleniumTest
[javac] selenium.stop();
[javac] ^
[javac] 21 errors

BUILD FAILED
C:\WorkSpace4Se\SampleTests\build.xml:21: Compile failed; see the compiler error
output for details.

Total time: 2 seconds

C:\WorkSpace4Se\SampleTests>

Regards,

Reply

seetaram March 24, 2012 at 9:30 am

I guess this is the problem of build path…by looking at the error messages… you need to fix the build path problem… for example you have added some jar files to build path inside your eclipse.. but ant is facing problem in finding them…

Reply

Ajith June 9, 2012 at 8:10 am

Hi Seetaram,

Firstly i Would like appreciate u for your kind responses to all..

even i m facing the same above issue as guru..so please can u elaborate ur above response by where and what exactly had to be done “to fix build path problem”.
screenshots or any docs pointing where exactly to fix would be much more appreciable…Please..

Reply

seetaram June 9, 2012 at 11:04 am

Hello Ajith,

To fix the build path issues. Right click on the project and then select properties. In properties window, click on build path, then click on library tab and then click external jars. Select all the jar files to be added to the project. This will fix the build path problem.

Reply

anurag parmar April 4, 2013 at 1:01 pm

Hi All self techies,

first I would like to thank Seetaram for sharing valuable knowledge for all fellow QAs.

@Guru, i have also face same problem as you have posted above.

I got the solution of this above problem, hope this will work for you and all others.

You have to create one folder named lib in directory where build.xml is placed.

Now copy all selenium jar files, which you have included in build path while configuring
eclipse for webdriver.

Now from command prompt again try to fire the build.

Reply

raj mohan April 26, 2012 at 1:01 pm

Hi guru,

Please include includeantruntime=”false”

And make sure you add the relevant files in Lib to Overcome error like package org.junit does not exist

Reply

shirisha July 11, 2013 at 12:22 pm

Hi Raj Mohan,

When I am executing build.xml file following error is displaying
C:\selenium\Scripts\SampleTests\lib does not exist.

Can you please explain about “lib” folder. Do we need to create “lib folder” manually in project(Sample project)??
When I created “lib” folder manually in project(SampleTests) folder and executing build.xml file then “package org.junit does not exists” type errors are displaying.

Displaying same error even when “includeantruntime=”false”” is included

It would be great if you could help me ASAP..

Thanks
Shirisha

Reply

Jeeva April 5, 2012 at 11:34 am

hi,
though i followed the given steps, ant is not invoked.. can u plz help me out??

Reply

seetaram April 16, 2012 at 12:34 pm

Can you provide me the error details…Otherwise, I will not be able to find out where you are stuck…

Reply

chalasani May 1, 2012 at 4:13 am

Hi Seetaram

This post was really awesome. This works really good. But can you please let me know how do I do this reporting stuff with testng? In build.xml, you were using . So is there any other tag for testng? Also can we do customization for the report? Like the report title is Unit Test Results. But I want it to be like Test Case Results. If so how can we do that?

Thanks

Reply

seetaram May 1, 2012 at 6:26 am

Yes… it is similar for TestNG… we can customize the test reports using style sheet… and include the style sheet ant report…

Reply

Sachin May 4, 2012 at 9:01 am

Hi Seetaram

I am using build.xml file to run my selenium tests. However the init task is failing to create the bin folder after deletion. Can you please guess why is this happening or is this a configuration issue of ant with eclipse?

Thanks,
Sachin

Reply

seetaram May 11, 2012 at 3:42 pm

can u give me your build file

Reply

Sachin May 15, 2012 at 11:25 am

Hi Seetaram,

Please find below the xml code I used for your reference. Thanks.

Reply

Sachin May 15, 2012 at 11:25 am
Sachin May 16, 2012 at 7:02 am

Seems like I am not able to paste the code here

Reply

Sachidanand Pramod Chaudhary June 23, 2012 at 5:57 pm

Hi Seetaram,

Thanks a lot for this good stuff any very easy way to create HTML test report. I was trying since two week finally I found this information and I got success. However I have one issue like I would like to run two seperate test scripts (.java like test suites). Is it possible using this code.

Thanks In Advanced

Sachi

Reply

seetaram June 29, 2012 at 4:08 pm

That is possible.. run two different Selenium server instances on different ports and then your selenium scripts should run on respective ports…

Reply

Chaithra July 2, 2012 at 11:28 am

Hi Seetaram,

Can u please give a detailed steps to generate reports using Eclipse+TestNG+Ant build?
I can able to generate reports using TestNG (running testng.xml).
My idea is to run test usinng Testng.xml and generate reports by running ant build file (build.xml)

thanks,
Chaithra

Reply

Mani December 20, 2012 at 11:55 pm

I am running the ant and instead of “com.selftechy.seltests.SeleniumTest” i gave my own test name which is under src/tests/Test123.java.

But ant is compiling all the tests under the tests folder, and i want to run only one test.

Can you tell me where i am doing a mistake …

Reply

Udayakumar December 21, 2012 at 11:44 am

Hi all,

I followed the same and it ran successfully.
But when tried the same with jenkins, it failed.
The error message is as follows:

Could not start Selenium session: Failed to start new browser session: org.openqa.selenium.os.WindowsRegistryException: Problem while managing the registry, OS Version ’6.1′, regVersion1 = false Build info: version: ‘unknown’, revision: ‘unknown’, time: ‘unknown’ System info: os.name: ‘Windows 7′, os.arch: ‘amd64′, os.version: ’6.1′, java.version: ’1.7.0′ Driver info: driver.version: unknown

I hope that you would help me with a solution or explain how error occured.
Thanks in advance

Reply

Rashmi January 2, 2013 at 10:38 am

Hi,
Thanks for such an explanation in simple lines.
Well, i am still facing a problem with the build.xml while running through command prompt.

Error is : Error running javac.exe compiler

The error is on 21st line of build.xml, please help me to resolve the same.

Reply

satya February 19, 2013 at 7:43 am

i am giving port no 4444 for my scripts.now i want to change the port no some 6666. there is any setup to change the port no and to run the test script

Reply

seetaram March 7, 2013 at 6:07 am

Use different port in the configuration

Reply

Subhasri March 5, 2013 at 10:49 am

Hi Seetaram,

Can you pls explain that wy cant we use the build.xml that has been generated by the eclipse itself instead of writing them all.
I’m using Selenium WebDriver and Junit.

Reply

seetaram March 7, 2013 at 5:54 am

Sure you can do it…:) But you miss learning writing your own build script.. It is always better to learn the things first and then use the tool so that if the tool gives you any error then will be able to understand the errors

Reply

Nazmul Hossain March 9, 2013 at 3:26 am

Hi SEETARAM,
Many thanks on a great tutorial. I am experiencing a little trouble with generating my report. I did everything about, copied your XML file and replaced your

with my own package name : ‘com.apleads.test’ and test class name: ‘TestClass’ . Basically, my target was set to

When executing the test, I come across this error:
“Class not found com.apleads.test.TestClass”

Please let me know what I can do to fix this as I am a novice in apache and junit. THANKS!!!

Reply

Nazmul Hossain March 9, 2013 at 3:29 am

I’m not sure why the target names aren’t showing in the message above. I basically changed your

test name=”com.selftechy.seltests.SeleniumTest” haltonfailure=”no” todir=”${report}/xml” outfile=”TEST-result”

with my

test name=”com.apleads.test.TestClass” haltonfailure=”no” todir=”${report}/xml” outfile=”TEST-result”

and i get the error:
Class not found com.apleads.test.TestClass”

Reply

seetaram August 26, 2013 at 6:14 am

Check the bin folder.. whether the TestClass is existing ?

Reply

Nitin March 11, 2013 at 9:39 am

Hi Seetaram,

It was a nice post from you. I have interest in learning Selenium automation. I checked here your example for generating reports for selenium 1.0 with junit4. Please can you post there another example with Selenium webdriver with junit4 with Ant build script. I tried but i failed to do so. Thanks in advance.

Reply

Sudhir Patil March 18, 2013 at 3:59 pm

Hi Seetaram,
We have Automation framework configured using Selenium Webdriver for our project. And use Junit as test engine and Aapache-ant to build and run the Java class files.
Ant generates a HTML-Junit report when Scripts run from console using Build.xml.

We are currently unable to get the required detailed output using ANT report.

We are looking to generate HTML report which provides detailed test results and also display in some interactive format to read and understand the results. For example the report should fulfill below,
· Summary of
1. Test case Passed
2. Test Failed
3. Test Not executed

· Detailed report displaying columns for
1. Test Case ID
2. Test Case Description [Irrespective of the class/function name]
3. Results /Status

will you please help me.

Reply

seetaram August 26, 2013 at 6:08 am

Design your own HTML report and generate that at the end of your execution. Dont use JUnit report.

Reply

Deuel Dias Lopes April 18, 2013 at 5:59 pm

Hi seetaram I have the following problem when a try to run the ant xml, any help will be very appreciated:

Setting environment for using XAMPP for Windows.

Administrador@STFJFC000658 c:\xampp
# cd C:\Documents and Settings\Administrador\Meus documentos\Projetos\Jenkins

Administrador@STFJFC000658 C:\Documents and Settings\Administrador\Meus document
os\Projetos\Jenkins
# ant
Buildfile: C:\Documents and Settings\Administrador\Meus documentos\Projetos\Jenk
ins\build.xml

init:
[delete] Deleting directory C:\Documents and Settings\Administrador\Meus docu
mentos\Projetos\Jenkins\bin
[mkdir] Created dir: C:\Documents and Settings\Administrador\Meus documentos
\Projetos\Jenkins\bin

compile:
[javac] C:\Documents and Settings\Administrador\Meus documentos\Projetos\Jen
kins\build.xml:21: warning: ‘includeantruntime’ was not set, defaulting to build
.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 1 source file to C:\Documents and Settings\Administrador\M
eus documentos\Projetos\Jenkins\bin
[javac] warning: [options] bootstrap class path not set in conjunction with
-source 1.6
[javac] 1 warning

exec:
[delete] Deleting directory C:\Documents and Settings\Administrador\Meus docu
mentos\Projetos\Jenkins\report
[mkdir] Created dir: C:\Documents and Settings\Administrador\Meus documentos
\Projetos\Jenkins\report
[mkdir] Created dir: C:\Documents and Settings\Administrador\Meus documentos
\Projetos\Jenkins\report\xml

BUILD FAILED
C:\Documents and Settings\Administrador\Meus documentos\Projetos\Jenkins\build.x
ml:36: java.lang.NoClassDefFoundError: junit/framework/TestResult
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.apache.tools.ant.AntClassLoader.findBaseClass(AntClassLoader.java
:1385)
at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:106
4)
at org.apache.tools.ant.util.SplitClassLoader.loadClass(SplitClassLoader
.java:58)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTaskMirrorImpl.newJ
UnitTestRunner(JUnitTaskMirrorImpl.java:66)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JU
nitTask.java:1390)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitT
ask.java:848)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeOrQueue
(JUnitTask.java:1899)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitT
ask.java:800)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
at org.apache.tools.ant.Main.runBuild(Main.java:851)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.ClassNotFoundException: junit.framework.TestResult
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
… 37 more

Total time: 2 seconds

Administrador@STFJFC000658 C:\Documents and Settings\Administrador\Meus document
os\Projetos\Jenkins
#

Reply

Prashanth May 3, 2013 at 11:33 am

Hi ,
Nice writeup.
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

Reply

nitin May 29, 2013 at 5:37 am

Hi Seetaram,

Please assist me where i am doing wrong, actually when i clicking TESTS-TestSuites.xml (being created when ant build got successful) in junit folder (report) giving me null argument error, i am using latest version of ant 1.9.1 junit 4.8.1 and eclipse platform 3.7.2.
Please let me know if you need more detail.
Any help would be appreciated.

Reply

nitin May 29, 2013 at 5:50 am

Sorry to ask again, i was actually want to know about index.html which is not being updated even after running successfully showing zero everything i.e., i have 2 different test running successfully but in reports it showing any test ran.

Summary (unit test result in index.html)
Tests Failures Errors Skipped Success rate Time
0 0 0 0 NaN 0.000

Please let me know if you need more detail.
Any help would be appreciated

Reply

shivanand H June 10, 2013 at 7:36 pm

Seetaram,
Thank you very much, I am using Windows 7, Selenium webdriver, Junit and ANT
to build html report, my build is successful, but I am unable to get the html report in any folders, please can u suggest me. Here below I have copied my code

—OutPut is
Buildfile: D:\Eclipse Indigo\shiva\build.xml
Test_class:
[junit] Running shiva_Pack.Test_class
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 17.444 sec
[junit] Output:
[junit] Start Class
[junit] Hello World
[junit] After Class
BUILD SUCCESSFUL
Total time: 18 seconds

I want this in HTML output in my I.E

Can u pls help me

Shiva

Reply

sakshi July 5, 2013 at 11:04 am

Thanks for the useful info.

C:\Users\admin\Desktop\selenium\Yahoo\Scripts\JavaProject\build.xml:22: C:\Users
\admin\Desktop\selenium\Yahoo\Scripts\JavaProject\lib does not exist.

Above error is displaying while executing, please answer

Reply

seetaram August 21, 2013 at 8:56 am

in the build.xml you might have been referring to lib folder. remove the reference.

Reply

Heather November 12, 2013 at 3:02 pm

Ur blog post, “Selenium – Use Ant to Generate HTML Reports” was in fact well
worth commenting down here in the comment section!
Merely desired to admit you really did a
great job. Thanks for your time ,Lyn

Reply

Santhoshkumar P January 29, 2014 at 7:39 am

Hi..

Am getting the following errors, Please solve this.. please past 3 days am trying the same..

[javac]
[javac] E:\HLUII-Testing\sqaforum\src\com\example\tests\FirstCase.java.java58: illegal start of expression
[javac]
[javac] ^
[javac] 100 errors

BUILD FAILED
E:\HLUII-Testing\sqaforum\build.xml:50: Compile failed; see the compiler error output for details.
Total time: 1 second

E:\HLUII-Testing\sqaforum>

Reply

seetaram January 29, 2014 at 11:43 am

This is a compilation error. Go to FirstCase.java and check the line 58 for any compilation mistakes. That will solve your problem

Reply

Leave a Comment

Previous post:

Next post:

Do you want to get updates on the recent articles written? Please subscribe to RSS feed or Email