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):
- Create a new project – SampleTests
- Create a new package (under src) – com.selftechy.seltests
- Under this package, create new Java class – SeleniumTest.java
- 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:
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…
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.
Thank you sitaram…..
it was very usefule
Jai.
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?
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.
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
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
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.
@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..
Hi seetram.,
Cau u sugesst how to generate xml file to generate the reports
regards.,
Babu.m
@babu
Create Report in XML format. For this you need to know how to create a file in XML format.
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.
Give me some more information on how do you generate build.xml file
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
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…
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,
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…
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..
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.
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.
Learning a ton from these neat arlcites.
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
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
hi,
though i followed the given steps, ant is not invoked.. can u plz help me out??
Can you provide me the error details…Otherwise, I will not be able to find out where you are stuck…
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
Yes… it is similar for TestNG… we can customize the test reports using style sheet… and include the style sheet ant report…
Unibaeevlble how well-written and informative this was.
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
can u give me your build file
Hi Seetaram,
Please find below the xml code I used for your reference. Thanks.
Seems like I am not able to paste the code here
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
That is possible.. run two different Selenium server instances on different ports and then your selenium scripts should run on respective ports…
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
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 …
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
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.
Sharp thikginn! Thanks for the answer.
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
Use different port in the configuration
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.
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
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!!!
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”
Check the bin folder.. whether the TestClass is existing ?
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.
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.
Design your own HTML report and generate that at the end of your execution. Dont use JUnit report.
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
#
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
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.
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
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
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
in the build.xml you might have been referring to lib folder. remove the reference.
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
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>
This is a compilation error. Go to FirstCase.java and check the line 58 for any compilation mistakes. That will solve your problem
Hi.
am using in selenium web driver to run Test cases using ant.. My build.xml file is run successfully.but some error in my reports file->xml ->TEST-com.goldencharm.selenium.Example.xml(type=”java.lang.ClassNotFoundException)
use Eclipse,firefox 28.0 and ubuntu 13.10
use jar files:-
junit-4.10.jar
selenium-server-standalone-2.39.0.jar
My code is:-
package com.goldencharm.selenium;
import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Example {
private WebDriver driver;
private String baseUrl;
// private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = “https://www.google.co.in/”;
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testUntitled2() throws Exception {
driver.get(baseUrl + “/”);
driver.findElement(By.id(“gbqfbb”)).click();
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!””.equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}
my build.xml file:-
Run Build.xml file using Ant in terminal:-
runTest:
[junit] Running com.goldencharm.selenium.Example
[junit] Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
[junit] Test com.goldencharm.selenium.Example FAILED
[junitreport] Processing /home/karamjeet/Projects/pulsetech-ofbiz/hot-deploy/golden-charm-ecommerce/reports/TESTS-TestSuites.xml to /tmp/null997507475
[junitreport] Loading stylesheet jar:file:/home/karamjeet/Projects/pulsetech-ofbiz/framework/base/lib/ant-junit-1.7.1.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 750ms
[junitreport] Deleting: /tmp/null997507475
BUILD SUCCESSFUL
Total time: 3 seconds
my report file error ->xml ->TEST-com.goldencharm.selenium.Example.xml
java.lang.ClassNotFoundException: com.goldencharm.selenium.Example
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
please help me
my build.xmxl file s:-
Hi all,
I am unable to run test by using ant build.xml.When i run tests through build.xml it is not through any error.I am stuck in middle of the road.Below is my out put:
Buildfile: C:\users\Janardhan\git\naukri_update\naukri_update\build.xml
setClassPath:
init:
clean:
[delete] Deleting directory C:\users\Janardhan\git\naukri_update\naukri_update\build
compile:
[echo] making directory…
[mkdir] Created dir: C:\users\Janardhan\git\naukri_update\naukri_update\build
[echo] classpath——: F:\drive d\selenium\jars\SaxonLiaison.jar:F:\drive d\selenium\jars\commons-beanutils-1.8.0.jar:F:\drive d\selenium\jars\derbyclient.jar:F:\drive d\selenium\jars\dom4j-1.1.jar:F:\drive d\selenium\jars\eclipselink-2.0.0.jar:F:\drive d\selenium\jars\flash-selenium.jar:F:\drive d\selenium\jars\javax.persistence-2.0.0.jar:F:\drive d\selenium\jars\log4j-1.2.14.jar:F:\drive d\selenium\jars\logging-selenium-1.2.jar:F:\drive d\selenium\jars\mail.jar:F:\drive d\selenium\jars\mysql-connector-java-5.0.7-bin(2).jar:F:\drive d\selenium\jars\poi-3.6-20091214.jar:F:\drive d\selenium\jars\poi-ooxml-3.6-20091214.jar:F:\drive d\selenium\jars\poi-ooxml-schemas-3.6-20091214.jar:F:\drive d\selenium\jars\saxon-8.7.jar:F:\drive d\selenium\jars\selenium-java-client-driver-sources.jar:F:\drive d\selenium\jars\selenium-java-client-driver-test-sources.jar:F:\drive d\selenium\jars\selenium-java-client-driver-tests.jar:F:\drive d\selenium\jars\selenium-java-client-driver.jar:F:\drive d\selenium\jars\selenium-server-coreless.jar:F:\drive d\selenium\jars\selenium-server-sources.jar:F:\drive d\selenium\jars\selenium-server.jar:F:\drive d\selenium\jars\testng-xslt-maven-plugin-test-0.0.jar:F:\drive d\selenium\jars\testng.jar:F:\drive d\selenium\jars\validation-api-1.0.0.GA.jar:F:\drive d\selenium\jars\xmlbeans-2.3.0.jar
[echo] compiling…
[javac] C:\users\Janardhan\git\naukri_update\naukri_update\build.xml:67: warning: ‘includeantruntime’ was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
[javac] Compiling 5 source files to C:\users\Janardhan\git\naukri_update\naukri_update\build
run:
[testng] [TestNG] Running:
[testng] C:\Users\Janardhan\git\naukri_update\naukri_update\testng.xml
[testng] ===============================================
[testng] Sample
[testng] Total tests run: 1, Failures: 1, Skips: 0
[testng] ===============================================
[testng] The tests failed.
But when i run my test through testng.xml as testng suite it was working fine.Below is my build.xml
<!–
–>
ant run will execute the test
Please help me………………………..
Here is my build.xml
<!–
–>
ant run will execute the test
Hi Seetaram
I am trying to run my scripts from ant tool. I followed the below steps in cmd
1)ant clean — build Success
2)ant compile — successful
3) ant run — Failed (configuration failure =1, skips= 8 )
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\IBM_ADMIN>cd C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_w
orspace\Z_1
C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_worspace\Z_1>ant clean
Buildfile: C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_worspace\Z_1
\build.xml
clean:
[delete] Deleting directory C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selen
ium\New_worspace\Z_1\build
BUILD SUCCESSFUL
Total time: 0 seconds
C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_worspace\Z_1>ant compil
e
Buildfile: C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_worspace\Z_1
\build.xml
setClassPath:
init:
clean:
compile:
[echo] making directory…
[mkdir] Created dir: C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\Ne
w_worspace\Z_1\build
[echo] classpath——: C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Seleniu
m\New_worspace\Z_1\Library\SaxonLiaison.jar:C:\Users\IBM_ADMIN\Desktop\Arun\Main
Folder\Selenium\New_worspace\Z_1\Library\dom4j-1.1.jar:C:\Users\IBM_ADMIN\Deskt
op\Arun\Main Folder\Selenium\New_worspace\Z_1\Library\poi-3.6-20091214.jar:C:\Us
ers\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_worspace\Z_1\Library\poi-oox
ml-3.6-20091214.jar:C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_wor
space\Z_1\Library\poi-ooxml-schemas-3.6-20091214.jar:C:\Users\IBM_ADMIN\Desktop\
Arun\Main Folder\Selenium\New_worspace\Z_1\Library\saxon-8.7.jar:C:\Users\IBM_AD
MIN\Desktop\Arun\Main Folder\Selenium\New_worspace\Z_1\Library\selenium-server-s
tandalone-2.47.1.jar:C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_wo
rspace\Z_1\Library\xmlbeans-2.3.0.jar
[echo] compiling…
[javac] Compiling 8 source files to C:\Users\IBM_ADMIN\Desktop\Arun\Main Fol
der\Selenium\New_worspace\Z_1\build
BUILD SUCCESSFUL
Total time: 2 seconds
C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_worspace\Z_1>ant run
Buildfile: C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_worspace\Z_1
\build.xml
setClassPath:
init:
clean:
[delete] Deleting directory C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selen
ium\New_worspace\Z_1\build
compile:
[echo] making directory…
[mkdir] Created dir: C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\Ne
w_worspace\Z_1\build
[echo] classpath——: C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Seleniu
m\New_worspace\Z_1\Library\SaxonLiaison.jar:C:\Users\IBM_ADMIN\Desktop\Arun\Main
Folder\Selenium\New_worspace\Z_1\Library\dom4j-1.1.jar:C:\Users\IBM_ADMIN\Deskt
op\Arun\Main Folder\Selenium\New_worspace\Z_1\Library\poi-3.6-20091214.jar:C:\Us
ers\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_worspace\Z_1\Library\poi-oox
ml-3.6-20091214.jar:C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_wor
space\Z_1\Library\poi-ooxml-schemas-3.6-20091214.jar:C:\Users\IBM_ADMIN\Desktop\
Arun\Main Folder\Selenium\New_worspace\Z_1\Library\saxon-8.7.jar:C:\Users\IBM_AD
MIN\Desktop\Arun\Main Folder\Selenium\New_worspace\Z_1\Library\selenium-server-s
tandalone-2.47.1.jar:C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_wo
rspace\Z_1\Library\xmlbeans-2.3.0.jar
[echo] compiling…
[javac] Compiling 8 source files to C:\Users\IBM_ADMIN\Desktop\Arun\Main Fol
der\Selenium\New_worspace\Z_1\build
run:
[testng] [TestNG] Running:
[testng] C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_worspace\
Z_1\testng.xml
[testng]
[testng] org.openqa.selenium.firefox.NotConnectedException: Unable to connect
to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
[testng] 1438847307351 addons.manager DEBUG Application has been upg
raded
[testng] 1438847307380 addons.manager DEBUG Loaded provider scope fo
r resource://gre/modules/addons/XPIProvider.jsm: [“XPIProvider”]
[testng] 1438847307382 addons.manager DEBUG Loaded provider scope fo
r resource://gre/modules/LightweightThemeManager.jsm: [“LightweightThemeManager”
]
[testng] 1438847307383 addons.xpi DEBUG startup
[testng] 1438847307384 addons.xpi DEBUG Skipping unavailable ins
tall location app-system-local
[testng] 1438847307384 addons.xpi DEBUG Skipping unavailable ins
tall location app-system-share
[testng] 1438847307387 addons.xpi DEBUG Ignoring file entry whos
e name is not a valid add-on ID: C:\Users\IBM_AD~1\AppData\Local\Temp\anonymous9
034237761840172033webdriver-profile\extensions\webdriver-staging
[testng] 1438847307402 addons.xpi DEBUG checkForChanges
[testng] *** Blocklist::_loadBlocklistFromFile: blocklist is disabled
[testng] 1438847307776 addons.xpi DEBUG Installed distribution a
dd-on IBM-cck@firefox-extensions.ibm.com
[testng] 1438847308779 addons.xpi DEBUG Installed distribution a
dd-on ietab@ip.cn
[testng] 1438847313445 addons.xpi DEBUG Installed distribution a
dd-on langpack-en-US@firefox.mozilla.org
[testng] 1438847317567 addons.xpi DEBUG Installed distribution a
dd-on langpack-es-ES@firefox.mozilla.org
[testng] 1438847321768 addons.xpi DEBUG Installed distribution a
dd-on langpack-fr@firefox.mozilla.org
[testng] 1438847325737 addons.xpi DEBUG Installed distribution a
dd-on langpack-it@firefox.mozilla.org
[testng] 1438847330315 addons.xpi DEBUG Installed distribution a
dd-on langpack-ja@firefox.mozilla.org
[testng] 1438847334228 addons.xpi DEBUG Installed distribution a
dd-on langpack-ko@firefox.mozilla.org
[testng] 1438847339337 addons.xpi DEBUG Installed distribution a
dd-on langpack-pt-BR@firefox.mozilla.org
[testng] 1438847343978 addons.xpi DEBUG Installed distribution a
dd-on langpack-zh-CN@firefox.mozilla.org
[testng] 1438847348284 addons.xpi DEBUG Installed distribution a
dd-on langpack-zh-TW@firefox.mozilla.org
[testng]
[testng] at org.openqa.selenium.firefox.internal.NewProfileExtensionConne
ction.start(NewProfileExtensionConnection.java:122)
[testng] at org.openqa.selenium.firefox.FirefoxDriver.startClient(Firefox
Driver.java:276)
[testng] at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDr
iver.java:116)
[testng] at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDrive
r.java:223)
[testng] at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDrive
r.java:216)
[testng] at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDrive
r.java:212)
[testng] at org.openqa.selenium.firefox.FirefoxDriver.(FirefoxDrive
r.java:125)
[testng] at com.apps.Main_Test.LaunchBrowser(Main_Test.java:15)
[testng] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[testng] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[testng] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Sourc
e)
[testng] at java.lang.reflect.Method.invoke(Unknown Source)
[testng] at org.testng.internal.MethodInvocationHelper.invokeMethod(Metho
dInvocationHelper.java:84)
[testng] at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker
.java:564)
[testng] at org.testng.internal.Invoker.invokeConfigurations(Invoker.java
:213)
[testng] at org.testng.internal.Invoker.invokeMethod(Invoker.java:653)
[testng] at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901
)
[testng] at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:12
31)
[testng] at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMe
thodWorker.java:127)
[testng] at org.testng.internal.TestMethodWorker.run(TestMethodWorker.jav
a:111)
[testng] at org.testng.TestRunner.privateRun(TestRunner.java:767)
[testng] at org.testng.TestRunner.run(TestRunner.java:617)
[testng] at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
[testng] at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
[testng] at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
[testng] at org.testng.SuiteRunner.run(SuiteRunner.java:240)
[testng] at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:
52)
[testng] at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
[testng] at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
[testng] at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
[testng] at org.testng.TestNG.run(TestNG.java:1057)
[testng] at org.testng.TestNG.privateMain(TestNG.java:1364)
[testng] at org.testng.TestNG.main(TestNG.java:1333)
[testng]
[testng] ===============================================
[testng] Arun_App
[testng] Total tests run: 4, Failures: 0, Skips: 4
[testng] Configuration Failures: 1, Skips: 7
[testng] ===============================================
[testng]
[testng] The tests failed.
BUILD SUCCESSFUL
Total time: 57 seconds
C:\Users\IBM_ADMIN\Desktop\Arun\Main Folder\Selenium\New_worspace\Z_1>
Thanks for sharing the useful information with us. This information is impressive..I am inspired with your post writing style & how continuously you describe this topic. After reading your post,thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
Thanks Savithaa