compiling returns error using ANt - ant

When I try to build my Selenium tests, getting BUILD failed message with the below errors. [I might be missing something in my build.xml] , could someone please have a look and let me know what am missing here plz.
I checked my build.xml, but didnt find a clue.
Errors:
7: package org.openqa.selenium.firefox does not exist
[javac] import org.openqa.selenium.firefox.FirefoxDriver;
[javac] ^
....
.............
BUILD FAILED
C:\Users\xxx\build.xml:70: Compile failed; see the compiler err
or output for details.
Here is my build.xml
<project name="myproj" default="usage" basedir=".">
<property name="ws.home" value="${basedir}" />
<!--<property name="ws.jars" value="${basedir}/lib" /> -->
<property name="ws.jars" value="C:\Jars" />
<property name="test.dest" value="${ws.home}/build" />
<property name="test.src" value="${ws.home}/src" />
<property name="ng.result" value="test-output" />
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="*.jar" />
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars"/>
</target>
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM/dd/yyyy hh:mm aa" />
</tstamp>
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition>
<taskdef name="testng" classpath="${test.classpath}"
classname="org.testng.TestNGAntTask" />
</target>
<!-- all -->
<target name="all">
</target>
<!-- clean -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compile -->
<target name="compile" depends="init, clean">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*" />
</delete>
</target>
<echo message="Making directory...."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath:... ${test.classpath}"/>
<echo message="${test.classpath}"/>
<echo message="compiling...."/>
<javac
includeantruntime="false"
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.6"
classpath="${test.classpath}">
</javac>
<!-- build -->
<target name="build" depends="init">
</target>
<!-- run -->
<target name="run" depends="compile">
<testng classpath="${test.classpath}:${test.dest}" suitename="Default suite">
<xmlfileset dir="${ws.home}" includes="testng.xml" />
</testng>
</target>
<!-- Usage -->
<target name="usage">
<echo>ant run will execute the test</echo>
</target>
<path id="test.c">
<filelist dir="${ws.jars}" includes="*.jar" />
</path>
<target name="makexsltreports">
<mkdir dir="${ws.home}/XSLT_Reports/output"/>
<xslt in="${ng.result}/testng-results.xml"
style="${ws.home}/testng-results.xsl"
out="${ws.home}/XSLT_Reports/output/index.html" >
<param name="testNgXslt.outputDir"
expression="${ws.home}/XSLT_Reports/output"/>
<param name="testNgXslt.showRuntimeTotals" expression="true" />
</xslt>
</target>
</project>

Related

ANT compile is working fine but ANT run not working build failed "failed to create task or type testng"

Below is my Build.xml file. when i compile my project it shows Build Success but when i run it then Build Failed "failed to create task or type testng" Cause: the name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
<?xml version="1.0" encoding="UTF-8"?>
<project name="projectName" default="clean" basedir="C:\Users\saad bin usman\workspace\testNG"> <!-- dot indicates that basedir is pointing towards project root directory -->
<!-- ========== Initialize Properties =================================== -->
<property name="ws.home" value="${basedir}" />
<property name="ws.jars" value="D:\jars" />
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="ng.result" value="test-output"/>
<echo> value of base dir = ${basedir} </echo>
<!-- properties for copying the results -->
<tstamp>
<format property="year" pattern="yyyy" />
<format property="DSTAMP" pattern="yyyy-MM-dd" />
<format property="TSTAMP" pattern="HH:mm:ss" />
<format property="dateversion" pattern="yyyy.MM.dd.HH:mm:ss" />
<format property="time.stamp" pattern="yyyy-MM-dd_HH-mm-ss aa_"/>
</tstamp>
<property name="testng.report.dir" value="${ws.home}/testngReports/${time.stamp}"/>
<property name="testngXslt.report.dir" value="${ws.home}/testngXsltReports/${time.stamp}"/>
<!-- ====== For setting the classpath ==== -->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes = "*.jar"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars" />
</target>
<!-- ============ Initializing other stuff =========== -->
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM-dd-yyyy (HH-mm-ss)"/>
</tstamp>
<condition property="ANT"
value="$(env.ANT_HOME)/bin/ant.bat"
else="$(env.ANT_HOME)/bin/ant">
<!-- os family="windows" /-->
<os family="mac" />
</condition>
<!--
<!- use direct path for classpath if you don't prefer to use 'lib' directory: classpath="/Users/yash/Documents/Jar Files/testng-6.8.jar" ->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="./lib/testng.jar"/>
</classpath>
</taskdef>
-->
</target>
<target name="all">
</target>
<!-- cleaning the destination folders -->
<target name="clean">
<echo message="deleting existing build directory"/>
<delete dir="${test.dest}"/>
</target>
<!-- target for compiling the java files -->
<target name="compile" depends="init, clean">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory....."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath-------: ${test.classpath}"/>
<echo message="compiling....."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
classpath="${test.classpath}"
includeantruntime="true"/>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<!-- ========== Test executions & Generating reports using Testng utility for multiple suites ============== -->
<!-- run -->
<target name="run" depends="compile">
<taskdef resource="testngtasks" classpath="D:\saad bin usman\saad's doc\softwares\eclipse\plugins\org.testng.eclipse_6.9.8.201510130443\lib\*.jar" />
<testng classpath="classpath.test" suitename="smsweb" outputDir="test-output" >
<xmlfileset dir="${ws.home}" includes="testng.xml" />
</testng>
</target>
<target name="testngReportCopyAndReportParser">
<!-- Copy to TestNG report directory-->
<mkdir dir="${testngDir}">
</mkdir>
<!-- to copy previous suite result to TestNG report directory -->
<copy todir="${testngDir}">
<fileset dir="test-output"/>
</copy> <!-- end of Testng Report -->
</target>
<!-- ========== Test executions & Generating reports using Testng XSLT utility for multiple suites ============== -->
<!-- run -->
<target name="runAsTestngXslt" depends="compile">
<!--suite 1 begin -->
<property name="suite.web.CopyRegressionCustomer" value="CopyRegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="CopyRegressionCustomer" outputDir="test-output" >
<xmlfileset dir="." includes="webSuites/CopyRegressionCustomer.xml" />
</testng>
<antcall target="testngXsltReportCopy">
<param name="testngXsltDir" value="${testngXslt.report.dir}${suite.web.CopyRegressionCustomer}"/>
</antcall>
<!--suite 2 begin -->
<property name="suite.web.Copy2RegressionCustomer" value="Copy2RegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="Copy2RegressionCustomer" outputDir="test-output" >
<xmlfileset dir="." includes="webSuites/Copy2RegressionCustomer.xml" />
</testng>
<antcall target="testngXsltReportCopy">
<param name="testngXsltDir" value="${testngXslt.report.dir}${suite.web.Copy2RegressionCustomer}"/>
</antcall>
</target>
<target name="testngXsltReportCopyAndReportParser">
<!-- Copy to TestNG report directory-->
<mkdir dir="${testngXsltDir}">
</mkdir>
<!-- to copy previous suite result to TestngXslt report folder -->
<xslt in="${ws.home}/test-output/testng-results.xml" style="src/xslt/testng-results.xsl"
out="${testngXsltDir}/index.html" classpathref="test.c" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${testngXsltDir}" />
<param name="testNgXslt.showRuntimeTotals" expression="true" />
<param name="testNgXslt.sortTestCaseLinks" expression="true" />
<param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS,CONF,BY_CLASS" />
</xslt> <!-- end of TestngXslt Report -->
</target>
<path id="test.c">
<fileset dir="${ws.jars}" includes="*.jar">
<include name="mail.jar"/>
<include name="activation-1.0.2.jar"/>
</fileset>
</path>
<!-- ========== Generating reports using Testng XSLT utility for single suite only ============== -->
<target name="report" depends="run">
<!-- TestngXslt report -->
<mkdir dir="${testngXslt.report.dir}">
</mkdir>
<!-- to copy previous suite result to TestngXslt report folder -->
<xslt in="${ws.home}/test-output/testng-results.xml" style="src/xslt/testng-results.xsl"
out="${testngXslt.report.dir}/index.html" classpathref="test.c" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${testngXslt.report.dir}" />
<param name="testNgXslt.showRuntimeTotals" expression="true" />
<param name="testNgXslt.sortTestCaseLinks" expression="true" />
<param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS,CONF,BY_CLASS" />
</xslt> <!-- end of TestngXslt Report -->
</target>
<target name="RunAndViewReport" depends="report">
<exec executable="${browser}" spawn="yes">
<arg line="'file:///${testngXslt.report.dir}/index.html'" />
</exec>
</target>
<target name="sendMail" depends="RunAndViewReport">
<zip destfile="${testngXslt.report.dir}/Report.zip" basedir="${testngXslt.report.dir}"/>
<mail mailhost="smtp.gmail.com" mailport="465" subject="Notification of TESTNG build result" ssl="false" user="automationmoolya#gmail.com" password="moolya#universe">
<from address="automationmoolya#gmail.com"/>
<to address="yagnesh#moolya.com"/>
<message>The build has finished. A details report of this build is attached</message>
<attachments>
<fileset dir="testngXslt.report.dir">
<include name="**/*.zip"/>
</fileset>
</attachments>
</mail>
</target>
<target name="install-jars" description="Install ANT optional jars">
<get dest="${ws.home}/lib/mail.jar" src="file:///${ws.home}/lib/mail.jar"/>
<fileset dir="${ws.jars}" includes="*.jar">
<include name="mail.jar"/>
<include name="activation-1.0.2.jar"/>
</fileset>
</target>
</project>
use run like below
<!-- run -->
<target name="run" depends="compile">
<testng classpath="${test.classpath}:${test.dest}">
<xmlfileset dir="${ws.home}" includes="testng.xml"/>
</testng>
</target>
Your taskdef is nested inside the task you're trying to use. That's now how it works. Define the task first, then run it.
<taskdef resource="testngtasks" classpath="/full/path/to/testng.jar" />
<testng classpathref="classpath.test" suitename="smsweb" outputDir="test-output" >
<xmlfileset dir="${ws.home}" includes="testng.xml" />
</testng>

Selenium: I am learning to send email report using ant build.xml . how to execute a java file using Ant

I am learning to send email report using ant build file, I need to know how to run a java file in ant build file. so how to execute a java file using Ant?
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>
<project name="Learning TestNG" default="usage" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="D:\jar"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="ng.result" value="${ws.home}/test-output"/>
<!--target name="start-selenium-server">
<java jar="${ws.home}/lib/selenium-server.jar"/>
</target-->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars"/>
</target>
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM/dd/yyyy hh:mm aa" />
</tstamp>
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition>
<taskdef name="testng" classpath="${test.classpath}"
classname="org.testng.TestNGAntTask" />
</target>
<!-- all -->
<target name="all">
</target>
<!-- clean -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compile -->
<target name="compile" depends="init, clean" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath------: ${test.classpath}"/>
<echo message="compiling..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.5"
classpath="${test.classpath}"
>
</javac>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<!-- run -->
<target name="run" depends="compile">
<testng classpath="${test.classpath}:${test.dest}" suitename="suite1">
<xmlfileset dir="${ws.home}" includes="testng.xml"/>
</testng>
<!--
<testng classpath="${test.classpath}:${test.dest}" groups="fast">
<classfileset dir="${test.dest}" includes="example1/*.class"/>
</testng>
-->
</target>
<target name="usage">
<echo>
ant run will execute the test
</echo>
</target>
<path id="test.c">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<target name="generateReports">
<mkdir dir="${ws.home}/XSLT_Reports/output"/>
<xslt in="${ng.result}/testng-results.xml" style="testng-results.xsl"
out="${ws.home}/XSLT_Reports/output/index.html" classpathref="test.c" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${ws.home}/XSLT_Reports/output/"/>
<param name="testNgXslt.showRuntimeTotals" expression="true"/>
</xslt>
</target>
<!-- ****************** targets not used ****************** -->
</project>

ANT BUILD ERROR : failed to create task or type testng

Hello, the problem is ,that i cannot trigger ANT run command in my
project , it gives me error. when i trigger ANT clean and ANT compile
, BUILD SUCCESS.
BUILD.XML CODE ERROR LINES
Getting the error on line :2
<!-- run -->
<target name="run" depends="compile">
<testng classpath="${test.classpath}:${test.dest}" suitename="suite1" outputDir="test-output" >
<xmlfileset dir="${ws.home}" includes="TestNG.xml" />
</testng>
<!--suite 1 begin -->
<property name="suite.web.CopyRegressionCustomer" value="CopyRegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="CopyRegressionCustomer" outputDir="test-output" >
<xmlfileset dir="${ws.home}" includes="TestNG.xml" />
</testng>
<antcall target="testngReportCopy">
<param name="testngDir" value="${testng.report.dir}${suite.web.CopyRegressionCustomer}"/>
</antcall>
ERROR LOG:
Problem: failed to create task or type testng
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any / declarations have taken place.
FULL BUILD.xml CODE
<?xml version="1.0" encoding="UTF-8"?>
<project name="projectName" default="clean" basedir="."> <!-- dot indicates that basedir is pointing towards project root directory -->
<!-- ========== Initialize Properties =================================== -->
<property name="ws.home" value="${basedir}" />
<property name="ws.jars" value="/Users/mac/Downloads/selenium-2.47.1" />
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="ng.result" value="test-output"/>
<echo> value of base dir = ${basedir} </echo>
<!-- properties for copying the results -->
<tstamp>
<format property="year" pattern="yyyy" />
<format property="DSTAMP" pattern="yyyy-MM-dd" />
<format property="TSTAMP" pattern="HH:mm:ss" />
<format property="dateversion" pattern="yyyy.MM.dd.HH:mm:ss" />
<format property="time.stamp" pattern="yyyy-MM-dd_HH-mm-ss aa_"/>
</tstamp>
<property name="testng.report.dir" value="${ws.home}/testngReports/${time.stamp}"/>
<property name="testngXslt.report.dir" value="${ws.home}/testngXsltReports/${time.stamp}"/>
<!-- ====== For setting the classpath ==== -->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes = "*.jar"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars" />
</target>
<!-- ============ Initializing other stuff =========== -->
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM-dd-yyyy (HH-mm-ss)"/>
</tstamp>
<condition property="ANT"
value="$(env.ANT_HOME)/bin/ant.bat"
else="$(env.ANT_HOME)/bin/ant">
<!-- os family="windows" /-->
<os family="mac" />
</condition>
<!--
<taskdef name="testng" classpath="/Users/mac/Downloads/selenium-2.47.1" classname="org.testng.TestNGAntTask" />
<!- use direct path for classpath if you don't prefer to use 'lib' directory: classpath="/Users/yash/Documents/Jar Files/testng-6.8.jar" ->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="./lib/testng.jar"/>
</classpath>
</taskdef>
-->
</target>
<target name="all">
</target>
<!-- cleaning the destination folders -->
<target name="clean">
<echo message="deleting existing build directory"/>
<delete dir="${test.dest}"/>
</target>
<!-- target for compiling the java files -->
<target name="compile" depends="init, clean">
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory....."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath-------: ${test.classpath}"/>
<echo message="compiling....."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
classpath="${test.classpath}"
includeantruntime="true"/>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<!-- ========== Test executions & Generating reports using Testng utility for multiple suites ============== -->
<!-- run -->
<target name="run" depends="compile">
<testng classpath="${test.classpath}:${test.dest}" suitename="suite1" outputDir="test-output" >
<xmlfileset dir="${ws.home}" includes="TestNG.xml" />
</testng>
<!--suite 1 begin -->
<property name="suite.web.CopyRegressionCustomer" value="CopyRegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="CopyRegressionCustomer" outputDir="test-output" >
<xmlfileset dir="${ws.home}" includes="TestNG.xml" />
</testng>
<antcall target="testngReportCopy">
<param name="testngDir" value="${testng.report.dir}${suite.web.CopyRegressionCustomer}"/>
</antcall>
<!--suite 2 begin -->
<property name="suite.web.Copy2RegressionCustomer" value="Copy2RegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="Copy2RegressionCustomer" outputDir="test-output" >
<xmlfileset dir="." includes="webSuites/Copy2RegressionCustomer.xml" />
</testng>
<antcall target="testngReportCopy">
<param name="testngDir" value="${testng.report.dir}${suite.web.Copy2RegressionCustomer}"/>
</antcall>
</target>
<target name="testngReportCopyAndReportParser">
<!-- Copy to TestNG report directory-->
<mkdir dir="${testngDir}">
</mkdir>
<!-- to copy previous suite result to TestNG report directory -->
<copy todir="${testngDir}">
<fileset dir="test-output"/>
</copy> <!-- end of Testng Report -->
</target>
<!-- ========== Test executions & Generating reports using Testng XSLT utility for multiple suites ============== -->
<!-- run -->
<target name="runAsTestngXslt" depends="compile">
<!--suite 1 begin -->
<property name="suite.web.CopyRegressionCustomer" value="CopyRegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="CopyRegressionCustomer" outputDir="test-output" >
<xmlfileset dir="." includes="webSuites/CopyRegressionCustomer.xml" />
</testng>
<antcall target="testngXsltReportCopy">
<param name="testngXsltDir" value="${testngXslt.report.dir}${suite.web.CopyRegressionCustomer}"/>
</antcall>
<!--suite 2 begin -->
<property name="suite.web.Copy2RegressionCustomer" value="Copy2RegressionCustomer" />
<testng classpath="${test.classpath}:${test.dest}" suitename="Copy2RegressionCustomer" outputDir="test-output" >
<xmlfileset dir="." includes="webSuites/Copy2RegressionCustomer.xml" />
</testng>
<antcall target="testngXsltReportCopy">
<param name="testngXsltDir" value="${testngXslt.report.dir}${suite.web.Copy2RegressionCustomer}"/>
</antcall>
</target>
<target name="testngXsltReportCopyAndReportParser">
<!-- Copy to TestNG report directory-->
<mkdir dir="${testngXsltDir}">
</mkdir>
<!-- to copy previous suite result to TestngXslt report folder -->
<xslt in="${ws.home}/test-output/testng-results.xml" style="src/xslt/testng-results.xsl"
out="${testngXsltDir}/index.html" classpathref="test.c" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${testngXsltDir}" />
<param name="testNgXslt.showRuntimeTotals" expression="true" />
<param name="testNgXslt.sortTestCaseLinks" expression="true" />
<param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS,CONF,BY_CLASS" />
</xslt> <!-- end of TestngXslt Report -->
</target>
<path id="test.c">
<fileset dir="${ws.jars}" includes="*.jar">
<include name="mail.jar"/>
<include name="activation-1.0.2.jar"/>
</fileset>
</path>
<!-- ========== Generating reports using Testng XSLT utility for single suite only ============== -->
<target name="report" depends="run">
<!-- TestngXslt report -->
<mkdir dir="${testngXslt.report.dir}">
</mkdir>
<!-- to copy previous suite result to TestngXslt report folder -->
<xslt in="${ws.home}/test-output/testng-results.xml" style="src/xslt/testng-results.xsl"
out="${testngXslt.report.dir}/index.html" classpathref="test.c" processor="SaxonLiaison">
<param name="testNgXslt.outputDir" expression="${testngXslt.report.dir}" />
<param name="testNgXslt.showRuntimeTotals" expression="true" />
<param name="testNgXslt.sortTestCaseLinks" expression="true" />
<param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS,CONF,BY_CLASS" />
</xslt> <!-- end of TestngXslt Report -->
</target>
<target name="RunAndViewReport" depends="report">
<exec executable="${browser}" spawn="yes">
<arg line="'file:///${testngXslt.report.dir}/index.html'" />
</exec>
</target>
<target name="sendMail" depends="RunAndViewReport">
<zip destfile="${testngXslt.report.dir}/Report.zip" basedir="${testngXslt.report.dir}"/>
<mail mailhost="smtp.gmail.com" mailport="465" subject="Notification of TESTNG build result" ssl="false" user="automationmoolya#gmail.com" password="moolya#universe">
<from address="automationmoolya#gmail.com"/>
<to address="yagnesh#moolya.com"/>
<message>The build has finished. A details report of this build is attached</message>
<attachments>
<fileset dir="testngXslt.report.dir">
<include name="**/*.zip"/>
</fileset>
</attachments>
</mail>
</target>
<target name="install-jars" description="Install ANT optional jars">
<get dest="${ws.home}/lib/mail.jar" src="file:///${ws.home}/lib/mail.jar"/>
<fileset dir="${ws.jars}" includes="*.jar">
<include name="mail.jar"/>
<include name="activation-1.0.2.jar"/>
</fileset>
</target>
</project>
Take a closer look at your ant-script, it use to define a TestNG ant task as:
<taskdef resource="testngtasks" classpath="testng.jar"/>
But in your case, you have this definition commented:
<!--
<taskdef name="testng" classpath="/Users/mac/Downloads/selenium-2.47.1" classname="org.testng.TestNGAntTask" />
<!- use direct path for classpath if you don't prefer to use 'lib' directory: classpath="/Users/yash/Documents/Jar Files/testng-6.8.jar" ->
<taskdef name="testng" classname="org.testng.TestNGAntTask">
<classpath>
<pathelement location="./lib/testng.jar"/>
</classpath>
</taskdef>
-->
You need to uncomment it or add a new one defenition to your script.

Ant build error : src does not exist

I was trying to run my build through Ant tool but console output always shows this error :
**E:\Automation\PowerElectronicsWorkShop\FreesunPortal\build.xml:31: srcdir "E:\Automation\PowerElectronicsWorkShop\FreesunPortal\${src.dir}" does not exist!
Build.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="" basedir="." default="runTests">
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="E:\Automation\Jar files\Jars"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="ng.result" value="test-output" />
<presetdef name="javac">
<javac includeantruntime="false" />
</presetdef>
<target name="setClassPath">
<path id="classpath_jars">
<fileset dir="E:\Automation\Jar files">
<include name="*.jar" />
</fileset>
<pathelement path="${class.path}" />
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars" />
</target>
<target name="clean" depends="setClassPath">
<echo message="deleting existing build directory"/>
<delete dir="${build.dir}"/>
<mkdir dir="${build.dir}"/>
</target>
<target name="compile" depends="clean">
<echo message="compiling.........."/>
<javac destdir="${build.dir}" debug="true" srcdir="${src.dir}" classpath="${test.classpath}"/>
</target>
<target name="runTests" depends="compile">
<taskdef resource="testngtasks" classpath="${test.classpath}"/>
<testng classpath="${test.classpath}:${build.dir}">
<xmlfileset dir="${basedir}" includes="testng.xml"/>
</testng>
</target>
</project>
I don't understand why this is occurring every time.
Add Following code under property tag
<property name="src.dir" location="src" />
<property name="build.dir" location="bin" />
Now you can re build your code through ANT, it will work.

Ant is not recognizing Log4j.properties file

I have been struck in this issue for past two days.Please help me in this. I am running my JUNIT scripts by using ANT. Reports are being generated, but ANT is not able to locate my log4j.properites file. When I am running through eclipse, logs are being generated. My problem here is I want logs when I am running through ANT.DO I need to set any properties.
What is the mistake I am doing?
Please help me.
My Log:
#Application Logs
#log4j.logger.devpinoyLogger
log4j.rootLogger=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.maxFileSize=5000KB
log4j.appender.dest1.maxBackupIndex=3
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n
log4j.appender.dest1.File=/Users/Application.log
#do not append the old file. Create a new log file everytime
log4j.appender.dest1.Append=false
build.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>
<project name="Module_Junit_Ant" default="usage" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="${ws.home}/jars"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="test.reportsDir" value="${ws.home}/reports"/>
<path id="testcase.path">
<pathelement location="${test.dest}"/>
<fileset dir="${ws.jars}">
<include name="*.jar"/>
</fileset>
</path>
<!--target name="start-selenium-server">
<java jar="${ws.home}/lib/selenium-server.jar"/>
</target-->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.jars}" includes="*.jar"/>
<fileset dir="${test.src}" includes="*.properties"/>
</path>
<pathconvert pathsep=":"
property="test.classpath"
refid="classpath_jars"/>
</target>
<target name="init" depends="setClassPath">
<tstamp>
<format property="start.time" pattern="MM/dd/yyyy hh:mm aa" />
</tstamp>
<condition property="ANT"
value="${env.ANT_HOME}/bin/ant.bat"
else="${env.ANT_HOME}/bin/ant">
<os family="windows" />
</condition>
</target>
<!-- all -->
<target name="all">
</target>
<!-- clean -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compile -->
<target name="compile" depends="init, clean" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.dest}" includes="**/*"/>
</delete>
<echo message="making directory..."/>
<mkdir dir="${test.dest}"/>
<echo message="classpath------: ${test.classpath}"/>
<echo message="compiling..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.5"
classpath="${test.classpath}"
>
</javac>
</target>
<!-- build -->
<target name="build" depends="init">
</target>
<target name="usage">
<echo>
ant run will execute the test
</echo>
</target>
<path id="test.c">
<fileset dir="${ws.jars}" includes="*.jar"/>
</path>
<target name="run" >
<delete includeemptydirs="true" quiet="true">
<fileset dir="${test.reportsDir}" includes="**/*"/>
</delete>
<java jar="${ws.jars}" fork="true" spawn="true" />
<junit fork="yes" haltonfailure="no" printsummary="yes">
<classpath refid="testcase.path" />
<!-- <classpath ="${test.classpath}"/> -->
<batchtest todir="${test.reportsDir}" fork="true">
<fileset dir="${test.dest}">
<include name="LogTest.class" />
<!--include name="tests/suite1/FirstSuiteRunner.class" />
<include name="tests/suite1/FirstSuiteRunner.class" /-->
</fileset>
</batchtest>
<formatter type="xml" />
<classpath refid="testcase.path" />
</junit>
<junitreport todir="${test.reportsDir}">
<fileset dir="${test.reportsDir}">
<include name="TEST-*.xml" />
</fileset>
<report todir="${test.reportsDir}" />
</junitreport>
</target>
<target name="email" >
<java classname="util.SendMail" classpath="${test.dest}" classpathref="testcase.path" />
</target>
</project>
Where are your log4j.properties located ?
What works for me it to put a
< pathelement location="x/y/z"/>
inside the
< path id="testcase.path">
which points to a folder which contains a log4j.properties!
So in this example your log4j.properties should be inside the 'z' folder!

Resources