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

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Josiah Lau
Solved:
2012-10-12
Last query:
2012-10-12
Last reply:
2012-10-11
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
System.getProperty("user.dir")

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!