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>
Related
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.
How can I generate HTML reports from JUnit using Ant when there are test failures?
The reports are generated when there are no failures.
Also, how can we define our own XSLT for the report generation?
build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="Ant Example" default="all" basedir=".">
<property name="project_name" value="junitSamples" />
<property name="src" location="src" />
<property name="build" location="build/classes" />
<property name="lib" location="lib" />
<property name="reports" location="reports" />
<target name="init" depends="clean">
<mkdir dir="${build}" />
<mkdir dir="${lib}" />
<mkdir dir="${reports}" />
<mkdir dir="${reports}/raw/" />
<mkdir dir="${reports}/html/" />
</target>
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${build}" description="compile the source code ">
<classpath>
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>
<target name="clean">
<delete dir="build" />
<delete dir="${reports}" />
</target>
<target name="run-tests" depends="compile">
<junit printsummary="yes" haltonfailure="yes" showoutput="yes">
<classpath>
<pathelement path="${build}" />
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</classpath>
<batchtest fork="yes" todir="${reports}/raw/">
<formatter type="xml" />
<fileset dir="${src}">
<include name="**/*Test*.java" />
</fileset>
</batchtest>
</junit>
</target>
<target name="test" depends="run-tests">
<junitreport todir="${reports}">
<fileset dir="${reports}/raw/">
<include name="TEST-*.xml" />
</fileset>
<report format="noframes" todir="${reports}\html\" />
</junitreport>
</target>
<target name="all" depends="clean, test" />
</project>
To specify your own stylesheets, use the "styledir" attribute:
<report styledir="${resources}/junit" format="..." todir="..." />
As noted, you must use the "junit-noframes.xsl" stylesheet name.
JUnit report docs.
You set haltonfailure="yes" it means that if one test fails build operation will stop.
This is from the ant documentation:
"Stop the build process if a test fails (errors are considered failures as well)."
Read more here- https://ant.apache.org/manual/Tasks/junit.html
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!
A project's building process is suffering, unless it becomes automatic.
I have started with ANTLR since recently. ANT seems to be the very building tool for that purpose. Compile, jar, and test... But I have found little code source of the script build.xml for that purpose.
So would you guys would like to share your template build.xml for your antlr project (either Java task or ANTLR task will be fine)? Thanks.
This is roughly what I use:
<?xml version="1.0" encoding="UTF-8"?>
<project name="YourProject">
<property name="main.package" value="yourproject"/>
<property name="parser.package" value="${main.package}/parser"/>
<property name="main.src.dir" value="src/main"/>
<property name="test.src.dir" value="src/test"/>
<property name="grammar.src.dir" value="src/grammar"/>
<property name="grammar.file" value="${grammar.src.dir}/YourGrammar.g"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="main.build.dir" value="${classes.dir}/main"/>
<property name="test.build.dir" value="${classes.dir}/test"/>
<path id="classpath">
<pathelement location="${main.src.dir}"/>
<pathelement location="${test.src.dir}"/>
<pathelement location="${main.build.dir}"/>
<pathelement location="${test.build.dir}"/>
<!-- the ANTLR jar is in the lib directory, of course -->
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>
<!-- init target -->
<target name="compile" depends="init" description="Compiles all source files.">
<javac srcdir="${main.src.dir}" destdir="${main.build.dir}" includeantruntime="false">
<classpath refid="classpath"/>
</javac>
<javac srcdir="${test.src.dir}" destdir="${test.build.dir}" includeantruntime="false">
<classpath refid="classpath"/>
</javac>
</target>
<target name="generate" depends="init" description="Generates the lexer and parser from the .g grammar file.">
<echo>Generating the lexer and parser...</echo>
<java classname="org.antlr.Tool" fork="true" failonerror="true">
<arg value="-fo"/>
<arg value="${main.src.dir}/${parser.package}"/>
<arg value="${grammar.file}"/>
<classpath refid="classpath"/>
</java>
<!--
compile the generated parser and lexer source file to see
if there's no illegal code inside these source files
-->
<antcall target="compile"/>
</target>
<!-- other targets -->
</project>
Here's the core pieces of mine, which I think integrates a little better. I'm not sure when ANTLR's -make option was added--I'm using 3.2.
It assumes that grammars are kept in the packages where their generated parsers will be going.
Keeps generated source files separate from normal source files so that they can be cleaned
Only regenerates parser+lexer sources when they are older than grammar file
multiple grammars can be processed in a single pass
ANTLR errors are reported correctly by ant
<project name="MyProject">
<property name="lib.antlr" value="lib/antlr-3.2.jar" />
<property name="src.dir" value="${user.dir}" />
<property name="src.java" value="${src.dir}/java" />
<property name="build.dir" value="build" />
<property name="build.src" value="${build.dir}/src" />
<property name="build.classes" value="${build.dir}/classes" />
<path id="compile.class.path">
<pathelement location="${build.classes}" />
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
</path>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${reports.dir}" />
</target>
<target name="generate" description="Generate parsers from ANTLR grammars">
<mkdir dir="${build.src}" />
<java jar="${lib.antlr}" fork="true" dir="${src.java}" failonerror="true">
<arg value="-verbose" />
<arg value="-make" />
<arg value="-o" />
<arg path="${build.src}" />
<arg value="com/example/io/Foo.g" />
<arg value="com/example/text/Bar.g" />
</java>
</target>
<target name="compile" depends="generate">
<property name="javac.debug" value="on" />
<mkdir dir="${build.dir}" />
<mkdir dir="${build.classes}" />
<javac destdir="${build.classes}" source="1.6" target="1.6" includeantruntime="false" debuglevel="lines,vars,source">
<src path="${src.java}" />
<src path="${build.src}" />
<include name="com/example/**/*.java" />
<classpath refid="compile.class.path"/>
</javac>
</target>
</project>
You can also look at How to use ant with ANTLR3.
I am trying to write an android build file that compiles, creates a jar executes it and also runs a bunch of test files. This is what I have so far, but not sure how to proceed with writing the test block. I have looked around but an example of a build file with junit testing but haven't found any..an example of a ant file with junit would be helpful please
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="test.dir" value="${build.dir}/test"/>
<property name="main-class" value="com.arkangelx.classes.ATMLauncher"/>
<property name="TALK" value="true" />
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" verbose="${TALK}"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="test" depends="run">
<mkdir dir="${test.dir}"/>
<test destfile="${test.dir}/${ant.project.name}.test" basedir="${build.dir}">
<junit>
<classpath refid="classpath.test" />
<formatter type="brief" usefile="false" />
<test name="TestExample" />
</junit>
</test>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
The test element must be a sub-element of the junit task. There are several exemples available in (surprinsingly) the documentation of the junit task.