when I run Ant in cmd it is showing me error of build.xml not exist while I have build.xml file in my project folder - ant

I am a selenium user trying to generate xslt reports using Ant, but when I run Ant in cmd it is showing me error of build.xml not exist while I have build.xml file in my project folder.
I am using eclispe juno on windows 7 and and kept the build.xml file under the project.
I have java JDK1.7 on my machine and I have already set the environment variables(Java and ant both) as per instructions given on apache.org
Ant version is apache-ant-1.9.1
I have imported all necessary jar files (selenium + maven +saxon + all required for xslt report through ant) in my project in eclipse.
When I am trying to run ant through cmd it is showing me this error:-
BUILD FAILED
D:\Projects\Project\Selenium\Workspace\build.xml:70: Compile failed; see the compiler error output for details.
Below is my build.xml file:-
<project name="Plumslice" default="usage" basedir=".">
<property environment="env"/>
<property name="ws.home" value="${basedir}"/>
<property name="ws.jars" value="D:\All 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="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.7"
classpath="${test.classpath}">
</javac>
<copy todir="${test.dest}">
<fileset dir="${test.src}" excludes="**/*.java"/>
</copy>
</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="email" >
<java classname="com.qtpselenium.util.SendMail" classpath="${test.dest}" classpathref="test.c" />
</target>
<target name="makexsltreports">
<mkdir dir="${ws.home}/XSLT_Reports/output"/>
<xslt in="${ng.result}/testng-results.xml" style="src/com/testing/xslt/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>
</project>

Thanks you all for your great help, I have resolved that error ..
It was related to the path of the jar files , I provided incorrect path to the jars.
This was line 70 : -
<javac debug="true" destdir="${test.dest}" srcdir="${test.src}"
target="1.7" classpath="${test.classpath}">
this is related to the path to the jars and in the top line of my file I did provided this path - D:\All jars , while all required jars was not in this folder, now I updated the jar folder and it is working fine now.

Related

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.xml not functioning properly

Below is a simplified versin of a build.xml for a Java project. It completes "build" correctly (creates the correct .class files) and prints out "Finishing build". It does not, however, print out "Starting jar". What am I not understanding? The target "jar" depends on "build", so it should be run next.
Running it with target release.
<?xml version="1.0"?>
<project name="Project" basedir="." default="release">
<!-- directories -->
<property name="src.dir" location="src/main/java"/>
<property name="cls.dir" location="private/classes"/>
<property name="lib.dir" location="lib"/>
<property name="jar.name" value="${ant.project.name}-${jar.ver}.jar"/>
<target name="clean" description="Delete all generated files">
<delete dir="${cls.dir}"/>
<delete dir="${lib.dir}"/>
</target>
<target name="build" depends="clean">
<mkdir dir="${cls.dir}"/>
<javac
destdir="${cls.dir}"
nowarn="off"
fork="yes"
debug="on">
<classpath>
<path path="${run.classpath}"/>
</classpath>
<src path="${src.dir}"/>
</javac>
<echo message="Finishing build"/>
</target>
<target name="jar" depends="build">
<echo message="Starting jar"/>
<mkdir dir="${lib.dir}"/>
<jar destfile="${lib.dir}/${jar.name}">
<fileset dir="${cls.dir}"/>
<fileset dir="${src.dir}" includes="**/*.properties"/>
<fileset dir="${src.dir}" includes="**/*.xml"/>
</jar>
</target>
<target name="release" depends="jar" description="Entry point">
</target>
</project>
Update the release target as follows to note that release depends on build then jar. i.e. depends="build,jar"
i.e.
<target name="release" depends="build,jar" description="Entry point">
<echo message="release ..."/>
</target>

TestNG test-output folder getting generated on Desktop when expected to be in project folder

I have a setup of Selenium WebDriver + TestNG + Ant framework in my automation project. Running webdriver + TestNG tests from Ant using build.xml was working absolutely fine a few months ago. TestNG was generating the test-output folder in the project directory as expected. Now when I run my testng tests from ANT it's generating the default report folder test-output on my Desktop (home/user/Desktop). I don't know why it is happening.
This is my build.xml file:
<project name="InitialConfigProject" default="start" basedir=".">
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property file="./app.properties"/>
<property name="ws.home" value="${basedir}"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="browser" value="/usr/bin/google-chrome"/>
<property name="mail_body_file" value="${basedir}/email_body.txt"/>
<property name="buildID" value="IND3.2.0"/>
<property name="sendmailscript_path" value="${basedir}/sendmail.sh"/>
<property name="mail_subject" value="Automated_test_execution_of_${buildID}"/>
<!-- ====== Set the classpath ==== -->
<target name="setClassPath" unless="test.classpath">
<path id="classpath_jars">
<fileset dir="${ws.home}/lib" includes="*.jar"/>
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars"/>
</target>
<!-- ============ Initializing other stuff =========== -->
<target name="init" depends="setClassPath">
<tstamp>
<format property="timestamp" pattern="dd/MM/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> -->
<property name="build.log.dir" location="${basedir}/buildlogs" />
<mkdir dir="${build.log.dir}"/>
<property name="build.log.filename" value="build_${timestamp}.log"/>
<record name="${build.log.dir}/${build.log.filename}" loglevel="verbose" append="false"/>
<echo message="build logged to ${build.log.filename}"/>
<echo message="Loading TestNG.." />
<taskdef name="testng" classpath="${test.classpath}" classname="org.testng.TestNGAntTask" />
</target>
<!-- cleaning the destination folders -->
<target name="clean">
<delete dir="${test.dest}"/>
</target>
<!-- compiling 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}"/>
<copy file="${ws.home}/app.properties" todir="${ws.home}/build" />
<copy file="${ws.home}/resources/testdata/testDataSet1.properties" todir="${ws.home}/build" />
<echo message="compiling source files..."/>
<javac
debug="true"
destdir="${test.dest}"
srcdir="${test.src}"
target="1.6"
classpath="${test.classpath}"
includeantruntime="true"
>
</javac>
</target>
<!-- run -->
<target name="run" depends="compile">
<testng outputdir="${ws.home}/test-output" classpath="${test.classpath}:${test.dest}" suitename="Praxify Sanity Suite">
<xmlfileset dir="${ws.home}" includes="testng.xml"/>
</testng>
</target>
<!-- ========== Generating reports using XSLT utility ============== -->
<target name="testng-xslt-report">
<delete dir="${basedir}/testng-xslt">
</delete>
<mkdir dir="${basedir}/testng-xslt">
</mkdir>
<xslt in="${basedir}/test-output/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html"
processor="SaxonLiaison">
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />
<param expression="true" name="testNgXslt.sortTestCaseLinks" />
<param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
<param expression="true" name="testNgXslt.showRuntimeTotals" />
<classpath refid="classpath_jars"></classpath>
</xslt>
</target>
<!-- Starting point of the execution, should be dependent on target "run".
Target sequence will be:
start (not_execute) ==> run (not_execute) ==> compile (not_execute) ==> init (execute) ==> clean (execute)
start (execute) <== testng-xslt-report (execute) <== run (execute) <== compile (execute) <==
Suitable for ANT 1.7. Currently using this ====================== -->
<target name="start" depends="run, testng-xslt-report">
<tstamp prefix="getTime">
<format property="TODAY" pattern="MM-dd-yyyyhhmmaa"/>
</tstamp>
<echo message="sending report as mail...."/>
<property name="execution_time" value="${buildID}_${getTime.TODAY}"/>
<property name="dest_file" value="/home/xtremum/Reports/${execution_time}.zip"/>
<zip destfile="/home/xtremum/Reports/${execution_time}.zip" basedir="${basedir}/testng-xslt"/>
<property name="report_attachment_file" value="${dest_file}"/>
<exec executable="${sendmailscript_path}" newenvironment="false">
<arg value="${mail_subject}"/>
<arg value="${mail_recipient}"/>
<arg value="${report_attachment_file}"/>
<arg value="${mail_body_file}"/>
</exec>
</target>
Just for the record:
1. I am using Eclipse Juno.
2. I have installed TestNG plugin on Eclipse so that I can run tests directly from eclipse by right clicking on testng.xml and going for Run.
3. I have installed ANT 1.7 on my Ubuntu machine and have set my ANT_HOME pointing to /usr/share/ant. And I looked up in Windows -> Preferences -> Ant -> Runtime -> Ant Home Entries (Default) and they seem to have references to ant 1.8.3 libraries (JARS) which are inside the Eclipse package (eclipse/plugins/). Is there anything wrong here?
4. I am running the tests via ant from eclipse and not from command line.
I am not getting any build errors. Tests are getting executed but the test-output folder is getting created on Desktop. Any help?
If you are running through the testng plugin option, the output folder would be the one you specify in Project->Properties->TestNG->OutputDirectory

Unable to find images when running selenium/sikuli scripts using Ant

I've written a couple selenium scripts (Java) and use sikuli to verify the images exist. It worked fine when I ran the tests through Eclipse/TestNG but with Ant I'm getting the following error:
[testng] [error] resources/x.png looks like a file, but can't be found on the disk. Assume it's text.
The following is my build.xml, please let me know if there's more information I can provide.
<project name="test" default="test">
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="lib.dir" location="lib" />
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="makedir" depends="clean">
<mkdir dir="${build.dir}" />
</target>
<!-- Compiles the java code -->
<target name="compile" depends="clean, makedir">
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath"/>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar destfile="${dist.dir}\build.test.ant.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="test.Main" />
</manifest>
</jar>
</target>
<taskdef resource="testngtasks" classpath="${lib.dir}/testng-6.5.2.jar"/>
<target name="test" depends="jar">
<testng
classpath="${build.dir}:${lib.dir}/selenium-java-2.24.1.jar:${lib.dir}/selenium-server-standalone-2.24.1.jar:${lib.dir}/sikuli-script.jar"
outputDir="${testng.report.dir}"
testname="test1">
<xmlfileset dir="." includes="testng.xml" />
</testng>
<fail message="BUILD FAILURE" if="failed" />
</target>
</project>

Ant not running all targets

I have the following ant file that is not running the targets "prepForDeployment" and "deployToStaging". This task is being run by Jenkins and I'm not getting any build errors when I look at the console output of the test.
<?xml version="1.0" encoding="UTF-8"?>
<project name="deploy" default="runUnitTests" basedir=".">
<description>
Deploys to staging.
</description>
<target name="init">
<taskdef name="mxunittask" classname="org.mxunit.ant.MXUnitAntTask" classpathref="project.classpath" />
<!-- dump the properties -->
<echoproperties prefix="test" />
</target>
<target name="clean" depends="init">
<mkdir dir="${test.junitoutput}" />
</target>
<target name="runUnitTests" depends="init,prepForTests">
<mkdir dir="${test.output.xml}/unit" />
<runTestDirectory directoryName="." excludes=""/>
</target>
<target name="runAllTests" description="Make output directories and run the MXUnit task" depends="init,clean,runUnitTests">
<!-- generate pretty reports -->
<antcall target="junitreport" />
<fail if="tests.bombed" message="Failing the build due to test failures"/>
</target>
<target name="junitreport" depends="init" description="Runs the report without running the tests">
<junitreport todir="${test.junitoutput}">
<fileset dir="${test.output.xml}">
<include name="*.xml" />
</fileset>
<report format="frames" todir="${test.junitoutput}" />
</junitreport>
</target>
<target name="prepForTests">
<!-- just a bunch of replace tasks, runs OK -->
</target>
<target name="prepForDeployment" depends="init">
<replace file="Application.cfc">
<replacetoken>dbcreate="dropcreate"</replacetoken>
<replacevalue>dbcreate="update"</replacevalue>
</replace>
<replace file="Application.cfc">
<replacetoken>logSQL = true</replacetoken>
<replacevalue>logSQL = false</replacevalue>
</replace>
<echo message="Prepping for deployment done." />
</target>
<target name="deployToStaging" depends="prepForDeployment">
<sequential>
<!--copy the files to a temp directory-->
<copy todir="${staging}_temp" overwrite="true">
<!-- -->
</copy>
<!-- delete applicaiton files on staging -->
<delete quiet="true" includeemptydirs="true">
<fileset dir="${staging}" />
</delete>
<!-- copy files from temp dir to application dir -->
<copy todir="${staging}" overwrite="true">
<fileset dir="${staging}_temp" />
</copy>
<!-- remove temp dir -->
<delete quiet="true" includeemptydirs="true">
<fileset dir="${staging}_temp" />
</delete>
</sequential>
<echo message="The files have been copied to staging." />
</target>
<macrodef name="runTestDirectory">
<attribute name="directoryName"/>
<attribute name="excludes" default=""/>
<sequential>
<mxunittask server="${test.server}" port="${test.serverport}" defaultrunner="${test.runner}" outputdir="${test.output.xml}/#{directoryName}" verbose="true" failureproperty="tests.bombed" errorproperty="tests.bombed">
<directory path="${test.dir.location}/#{directoryName}" recurse="true" packageName="${test.cfcpath}.#{directoryName}" componentPath="${test.cfcpath}.#{directoryName}" excludes="#{excludes}" />
</mxunittask>
</sequential>
</macrodef>
</project>
If you're not telling Jenkins to run the prepForDeployment and deployToStaging targets then it won't run them, just the same as when you run Ant on the command line.
If you want those targets to run, add them to the target list under your "Invoke Ant" build step.

Resources