ANT compilation error on updating selenium test result on TestLink - testlink

I am trying to run the TestNG tests using ANT. ANT executes it fine and creates an xslt report. When I add code in TestNg test to update Testlink ANT compilation fails with an error:
error: cannot find symbol import org.apache.xmlrpc.XmlRpcConfig;
^
symbol: class XmlRpcConfig
location: package org.apache.xmlrpc
1 error
BUILD Failed.
If I run TestNg.xml directly it updates everything in Testlink. Already imported xmlrpc.jar,xml-apis-1.4.01.jar,xmlrpc-client-3.1.3.jar in my project LIB folder.
Snippet from Build.xml --
<property environment = "env"/>
<property name="project.dir" value="${basedir}"/>
<property name="build.dir" value="${basedir}/build"/>
<property name="jar.dir" value="${basedir}/Lib"/>
<property name="src.dir" value="${basedir}/src"/>
<property name="ng.result" value="test-output"/>
<tstamp>
<format property="TODAY_AU" pattern="d-MMMM-yyyy" locale="en,GB"/>
</tstamp>
<target name="setClassPath">
<path id="classpath_jars">
<pathelement path="${basedir}/" />
<fileset dir="${jar.dir}">
<include name="*.jar"/>
</fileset>
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars" />
</target>
<target name="TestNg" depends="setClassPath" >
<taskdef resource="testngtasks" classpath="${test.classpath}"/>
</target>
Kindly help.

Related

Rename a file before Copy Task in ant build

I am new to ant build files.
Currently I get a list of files for build as:
a.cls
b.cls
c.cls
but in my local I have to run build on files, in the same directory:
a-meta.cls
b-meta.cls
c-meta.cls
Here meta keyword stays consistent. And I am using the following build.xml file. I am not sure how can I rename filename before actually copying them. I tried replace, mapper and other antlib tasks. But not helpful.
<project name="test" default="compile">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<loadfile property="file" srcfile="filesToMove.txt"/> <!-- these are the list of files, i mentioned earlier -->
<target name="compile">
<echo>${file}</echo> <!-- here i have to rename file name to include -meta -->
<copy file="./classes/${file}" tofile="./src/classes/${file}" overwrite="true"/>
</target>
</project>
How to rename the files before moving them.
The solution to it was replacing the .cls to find only the name and then append the -meta.html. As follows (some portion is changed compared to previous version in the question)
<project name="test" default="compile">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<loadfile property="file" srcfile="filesToMove.txt"/> <!-- these are the list of files, i mentioned earlier -->
<target name="compile">
<echo>${file}</echo> <!-- here i have to rename file name to include -meta -->
<copy file="./classes/${file}" tofile="./src/classes/${file}" overwrite="true"/>
<for param="file">
<path>
<fileset dir="./" includes="*.cls"/>
</path>
<sequential>
<basename file="#{file}" property="#{file}" suffix=".md"/>
<echo message=" ${#{file}}"/>
<copy file="${#{file}}-meta.cls" toDir="test"/>
</sequential>
</for>
</target>
</project>

Jnuit and Code files in different locations

I am trying to run ANT script to execute a simple junit test case.
Now I have a requirement.
The executable file with my sample product will be in one location
My junit test cases will be in another location
Still I have to sync up and get the test case executed
Is there a way where I can ask my Junit to look another location for source.
If your junit test cases live in another project then you will need to create a seperate build.xml for that project setup for unit tests. Make sure this new build.xml references your sample product JAR as a dependency.
Yes this is possible.
Compile your source files as usual:
<javac srcdir="../${srcDir}/src" destdir="dist/src">
Compile your test files, including the compiled source in your classpath:
<javac srcdir="../${testDir}/test" destdir="dist/test">
<classpath location="dist/src"/>
</javac>
Then include both these in the JUnit classpath:
<path id="junit.path">
<pathelement location="dist/src" />
<pathelement location="dist/test" />
<fileset file="../Libraries/junit*.jar" />
<fileset file="../Libraries/ant-junit*.jar" />
<fileset dir="externalLibraries">
<include name="**/*.jar" />
</fileset>
</path>
<junit fork="yes" forkmode="once">
<classpath refid="junit.path" />
<batchtest fork="yes" todir="${dist}/testresults">
<fileset dir="dist/test">
<include name="**/*Test.class" />
</fileset>
</batchtest>
</junit>
See also Ant documentation

Nant wont recognize namespace.Properties

I'm trying to use nant to build a solution for a c# project however I am having an issue specifying resources in my build file. I get the error code:
CS0234: The type or namespace name 'Properties' does not exists in the namespace 'Darkside'. How can I modify my build file to remove the error?
Here is one of the snippets of code in my source files that is causing the issue:
Image enemyImage = DarkSide.Properties.Resources.DarkSide_Asteroid_Medium_Gray;
where Darkside is the namespace of the project, and the rest accesses the resources
Here is a snippet of my build file:
<target name="build" depends="init" description="compiles the source code">
<property name="build.dir" value="${project::get-base-directory()}/${project::get-name()}/bin/release/${project.version}${basedir.suffix}"/>
<mkdir dir="${build.dir}"/>
<csc target="exe" output="${build.dir}/Darkside.exe" debug="${build.debug}">
<sources>
<include name="Darkside/*.cs"/>
</sources>
<resources >
<include name="${project::get-base-directory()}/${project::get-name()}/Properties/**" />
</resources>
</csc>
</target>
You should probably define the prefix for the resources tag (with dynamicprefix="true").
<target name="build" depends="init" description="compiles the source code">
<property name="build.dir" value="${project::get-base-directory()}/${project::get-name()}/bin/release/${project.version}${basedir.suffix}"/>
<mkdir dir="${build.dir}"/>
<csc target="exe" output="${build.dir}/Darkside.exe" debug="${build.debug}">
<sources>
<include name="Darkside/*.cs"/>
</sources>
<resources dynamicprefix="true" prefix="DarkSide">
<include name="${project::get-base-directory()}/${project::get-name()}/Properties/**" />
</resources>
</csc>
</target>
Indeed the csc task's documentation states:
Note: In order to have <csc> task generate manifest resource names that match those generated by Microsoft Visual Studio.NET, the value of the prefix attribute of the <resources> element should match the "Default Namespace" of the C# project, and the value of the dynamicprefix attribute should be set to "true".

Javac exclusion of package in ANT build.xml

I'm trying to compile all my packages except two of them, here is what my javac in build.xml looks like
<javac srcdir="${src}" destdir="${output}" debug="${debug}" failonerror="yes" >
<exclude name="com/abc/uyyy/**"/>
<exclude name="com/abc/zzz/**"/>
<include name="com/abc/zzz/Text.java"/>
<patternset refid="excluded.from.compilation.abc"/>
<classpath refid="abc.module.classpath"/>
</javac>
But all the files in package are compiled :(.
I've read the documentation (http://ant.apache.org/manual/Tasks/javac.html), but still no success, any help?
NOTE: After the Text.java is compiled, I need to build the WSDL file and then build the excluded packages. I'm using Metro to write and build my WS.
Is it not possbile to compile all the class files into one directory, then use the copy task like below to only copy the ones you want for WSDL?
<target name="copy_all_class_files">
<copy todir="${output}">
<fileset dir="classes">
<include name="com/abc/zzz/Text.class"/>
<exclude name="com/abc/uyyy/**"/>
<exclude name="com/abc/zzz/**"/>
</fileset>
</copy>
</target>
Ok here is what I did,I wrote a new target to compile only the WS file and then generate the classes, it works fine :)
<target name="compile-ws-server">
<javac srcdir="${src}" destdir="${output}"
debug="${debug}" failonerror="yes">
<include name="com/abc/xxx/Text.java"/>
<exclude name="${src}/abc/xxx/**"/>
<classpath refid="abc.module.classpath"/>
</javac>
</target>
All Above is not proper way ...
I have done like
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${build}" excludes="com/company/example/test/**" />
</target>
Here we should avoid placing ${src} and start from inside src folder.

Email notification on success/failed build using ant target

my current code(build.xml) enables me to send email on successful build, but when failed, nothing happens. The targets are called from a build.bat file through command similar to " ........ -DrepositoryAddress=%1 -DbuildResultUUID=%2 startPublish " (for all targets, in order startActivity->startPublish->mailer->startActivity).
Now, I also want email notification when the build fails.I guess trycatch will help me get the task done, but HOW? Not sure about it, where/how to place it(edit it?)? I kind of used trycatch, it gave me something like " Problem: failed to create task or type trycatch" . What modifications are required in current script/xml file to enable this functionality of sending email indicating status of build (successful or failed). Please guide/help.Thanks so much.
'
<target name="startActivity">
<fail message="Missing repositoryAddress" unless="repositoryAddress"/>
<fail message="Missing buildResultUUID" unless="buildResultUUID"/>
<fail message="Missing activityLabel" unless="activityLabel"/>
<!-- Replace ADMIN with your real credentials. -->
<startBuildActivity
buildResultUUID="${buildResultUUID}"
label="${activityLabel}"
autoComplete="true"
repositoryAddress="${repositoryAddress}"
userId="BuildAdmin"
password="Abc1234"/>
</target>
<target name="startPublish">
<sleep seconds="10"/>
<fail message="Missing repositoryAddress" unless="repositoryAddress"/>
<fail message="Missing buildResultUUID" unless="buildResultUUID"/>
<artifactfilePublisher repositoryAddress="${repositoryAddress}"
userId="BuildAdmin"
password="Abc1234"
buildResultUUID="${buildResultUUID}"
filePath="E:\Setup.msi"
label="Installer" />
</target>
<target name="mailer">
<property name="report" value="E:\Report.html"/>
<mail from="dmin#company.com" messagemimetype="text/html" charset="ISO-7779-1" messagefile="${report}" mailhost="HMMMM.company.com" mailport="25" tolist="admin#company.com" subject="Build status" />
</target>
<taskdef name="startBuildActivity"
classname="com.ibm.team.build.ant.task.StartBuildActivityTask" />
<taskdef name="artifactfilePublisher"
classname="com.ibm.team.build.ant.task.ArtifactFilePublisherTask" />
</project>'
you can implement a BuildListener that sends the email as described in the ant FAQ