sikuli in custom module?

Asked by sotn3m

What should I do (import something?) to be able to use sikuli commands (wait, click, dragDrop etc.) and objects in a custom module?

I am using windows xp and sikuli 0.10.
I issue the test by running "java -classpath sikuli-script.jar test.sikuli" in the command line.
So far I have created a file "helpers.py" in "lib" directory and imported it, but sikuli objects are not visible.

import sys
import unittest
import helpers

setAutoWaitTimeout(5000)
setThrowException(False) # no exception raised, not found returns None

class MyTests(unittest.TestCase):
    ...
    ...

suite = unittest.TestLoader().loadTestsFromTestCase(MyTests)
unittest.TextTestRunner(verbosity=3).run(suite)
popup("Testing finished")

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Andrzej Wiech (andrjus-w) said :
#1

I have similar problem, I am trying to run sikuli from Java and it looks like methods click, wait, dragDrop have been moved to Region class, it used to be in SikuliScript class. Also I have not managed to run unit tests either from python or java. There seems to be a problem with tmplib forlder which used to had to be in the place where script was run. I unpacked sikuli-script.jar and sikuli-ide.jar and the structure is different now, there is folder Frameworks with all lib files, I put in my project, but here is what I get:.

Exception in thread "main" java.lang.UnsatisfiedLinkError: /Users/andrzejw/Documents/workspace/sikuli-tests/tmplib/libScreenMatchProxy.jnilib: Library not loaded: @executable_path/../Frameworks/libcxcore.4.dylib Referenced from: /opt/local/lib/libcv.4.dylib Reason: image not found

Is there a chance to set it up somehow as Sikuli IDE is useless for more advanced testing, when you need to have mechanism to create suite, way to debug etc.

Revision history for this message
Andrzej Wiech (andrjus-w) said :
#2

I can see there was the same problem in previous version:
https://answers.launchpad.net/sikuli/+question/101506
Maybe I just forgot that I had to take it from source. The problem is that I cannot find up to date source code. Anyone know where this is reachable. This seems to be out of date : http://bazaar.launchpad.net/~vgod/sikuli/trunk/files

Andrzej

Revision history for this message
Andrzej Wiech (andrjus-w) said :
#3

Sorry I pressed wrong button.

Revision history for this message
Tsung-Hsiang Chang (vgod) said :
#4

If you use sikuli-script.jar alone, the jnilibs should be extracted from the JAR to tmplib/ automatically.
Here is a quick way to test if it works.

$ java -cp sikuli-script.jar org.python.util.jython
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)[Java HotSpot(TM) Client VM (Apple Inc.)] on java1.6.0_17
Type "help", "copyright", "credits" or "license" for more information.
>>> from sikuli.Sikuli import *
ScreenMatchProxy loaded.
VDictProxy loaded.
ScreenMatchProxy loaded.

If you see the three lines "xxx loaded", it is working. One problem you may encounter is that the jnilibs complain UnsatisfiedLinkError because they can't find opencv libs in /opt/local/lib. To resolve this, you can simply install opencv using DarwinPorts (port install opencv), or you can copy *.dylib's from Sikuli-IDE.app/Contents/Frameworks and use install_name_tool to change their reference path. (Sikuli-IDE.app/Contents/Frameworks/change-lib-path.sh will show you how to do that.)

Revision history for this message
Jeremiah Jacquet (jeremiahjacquet) said :
#5

I am still having an issue with install I have copied the dylibs to the Java project in a folder called "Frameworks" and I also copied the script to that same location. I then copied the jnilibs toa folder called "tmplib also within the Java project. When I tried to run the script "change-lib-path.sh" i get the following error:

otool: can't open file: *.jnilib (No such file or directory)

do i need to modify the scipt? if so, what needs to be changed?

additionally, under the root directory where the Sikuli-IDE.app live i ran the following:
java -jar /Applications/Sikuli-IDE.app/Contents/Resources/Java/sikuli-script.jar -i

and recieved this error:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
 at java.lang.String.substring(String.java:1937)
 at edu.mit.csail.uid.ScriptRunner.getPyFrom(ScriptRunner.java:87)
 at edu.mit.csail.uid.ScriptRunner.runPython(ScriptRunner.java:81)
 at edu.mit.csail.uid.SikuliScript.main(SikuliScript.java:76)

Revision history for this message
RaiMan (raimund-hocke) said :
#6

@ Jeremiah
You are using an outdated version of Sikuli.
When using the latest version of Sikuli (which is recommended) on Mac, then nothing else has to be done, than to have the bundle Sikuli-IDE.app in the folder /Applications. Every thing, that Sikuli needs is found then automatically in all cases. It simply runs out of the box.

Revision history for this message
Jeremiah Jacquet (jeremiahjacquet) said :
#7

Thanks RaiMAn, I did download the latest Sikuli X-1.0rc3 (r930) osx-10.6.dmg to the new machine I'm trying to setup. The problem was I pulled down my java project from my github repo that is using older dylib and jnilibs from a bundle version declaring "X-1.0rc2" so that would explain that.

I will just blow away the old tmplib and Framework folders I have in my java project containing the older dylib and jnilibs, and replace the old sikuli-ide.jar , sikuli-script.jar too with all the latest from Sikuli X.

Final question though before I upgrade to the latest Sikuli. You mentioned Sikuli X should "work out of the box", however on your github site your you list Prerequisites:

   XCode
   CMake 2.8+
   OpenCV 2.1+
   Tesseract-OCR 2.04 + English language data (3.0 won't work),
   SWIG 1.3+

I have the Xcode part on this new machine . So the last question is:

Should I install opencv, etc? or just download the latest .dmg file and follow the instructions here: http://doc.sikuli.org/faq/030-java-dev.html ?

Revision history for this message
RaiMan (raimund-hocke) said :
#8

@ Jeremiah
This prereq stuff is only needed, if you would decide to build your own Sikuli from the sources.

So for your needs just copy the Sikuli-IDE.app from the .dmg to the /Applications folder and start using it.

For Java programming:
- have sikuli-script.jar on your class path
- use import org.sikuli.script.* in your Java

Can you help with this problem?

Provide an answer of your own, or ask sotn3m for more information if necessary.

To post a message you must log in.