Unable to find images when running scripts using Ant

Asked by Josiah Lau on 2012-10-10

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" />

 <target name="clean">
  <delete dir="${build.dir}" />

 <target name="makedir" depends="clean">
  <mkdir dir="${build.dir}" />

 <!-- Compiles the java code -->
 <target name="compile" depends="clean, makedir">
  <javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath"/>

 <!--Creates the deployable jar file -->
 <target name="jar" depends="compile">
  <jar destfile="${dist.dir}\build.test.ant.jar" basedir="${build.dir}">
    <attribute name="Main-Class" value="test.Main" />

 <taskdef resource="testngtasks" classpath="${lib.dir}/testng-6.5.2.jar"/>

 <target name="test" depends="jar">
    <xmlfileset dir="." includes="testng.xml" />
   <fail message="BUILD FAILURE" if="failed" />


Question information

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Josiah Lau
Last query:
Last reply:
RaiMan (raimund-hocke) said : #1

Sikuli cannot find the image files in the standard places it is looking for (so it tries to use the image filenames as text to search on the screen - I personally do not like this standard behavior ;-)

You have to use one of the available means to set the imagepath (e.g. addImagePath() or -DIMAGE_PATH=... on the java commandline).

Josiah Lau (lau-josiah) said : #2

This is what I have in my method and I'm still getting the same error:

public void verifyImage() throws Exception {
   ImageLocator.addImagePath("resources/"); <-- Added
   s.doubleClick("x.png"); <-- originally 's.doubleClick("resources/x.png");'

I'm running this in Mac and the src directory is on the same level as the resources directory. Please let me know what other information I can provide. Thanks.

Josiah Lau (lau-josiah) said : #3

The modified code works when I run it from Eclipse/TestNG

RaiMan (raimund-hocke) said : #4

Since you are using relative path specification, the base path must be different in both situations.

You might get the current working directory

Based on this you can create an absolute path for the addImagePath().

Josiah Lau (lau-josiah) said : #5

After further investigation, I found out that the issue is only happening if I run the ant file through Eclipse. Using your suggestion I was able to pull the directory and it shows as /Applications/Eclipse/Eclipse.app/Contents/MacOS. So if I run the ant file in command line I'm not having the issue.

Thanks for the help!