Running tests using Python's unittest --- to be adapted to version X-1.0

Asked by Peter Parente on 2010-02-09

**** Take care **** For people who read through this really impressive and helpful thread:

It starts based on version 0.9x and ended with version 0.10.1

While the basics concerning Python unittest are still valid, things regarding the Sikuli features, usage and environment have to be checked, when working with Sikuli X-1.0.

***************************************************************
The following method works on Mac and Windows.

1) Write a real unit test using PyUnit.

import sys
import unittest
# setAutoWaitTimeout(5000) # till version 0.9x
setAutoWaitTimeout(5) # beginning with version 10.x and for X-1.0

class MyTests(unittest.TestCase):
   def setUp(self):
      switchApp("/Applications/Safari.app")
      # @todo: do similar for IE on Windows

   def tearDown(self):
      pass

   def testNewTab(self):
      type("t", KEY_META)
      type("https://answers.launchpad.net/sikuli/+question/99979\n")
      m = find("sikuli-logo.png")
      assert(m is not None and m.getScore() > 0.9)

suite = unittest.TestLoader().loadTestsFromTestCase(MyTests)
unittest.TextTestRunner(verbosity=2).run(suite)

2) Save your unit test as a Python script in a folder with a matching name and .sikuli suffix (e.g., mytest.sikuli/mytest.py).

3) Download the cross-platform, command line tool version of Sikuli from http://groups.csail.mit.edu/uid/sikuli/download.shtml.

4) Extract the contents of the command line tool zip.

On Windows:

4) Download the Windows IDE version of Sikuli.

5) Extract the Lib/ folder from the sikuli-ide-full.jar.

6) Move the Lib/ folder into the same directory as the sikuli-script.jar from the command line tool version of Sikuli.

7) Execute your test script like so (assuming cygwin):

export PATH=$PATH:./win32
java -Dpython.path=Lib/ -jar sikuli-script.jar mytest.sikuli 2> test-output.log

8) The test-output.log contains the results of the unit test run while stdout shows the sikuli logging info.

On Mac:

4) Download the Mac IDE version of Sikuli.

5) Extract the Lib/ folder from the Sikuli.app/Contents/Resources/Java/sikuli-script.jar.

6) Move the Lib/ folder into the same directory as the sikuli-script.jar from the command line tool version of Sikuli.

7) Execute your test script like so:

java -d32 -Dpython.path=Lib/ -jar sikuli-script.jar mytest.sikuli 2> test-output.log

8) The test-output.log contains the results of the unit test run while stdout shows the sikuli logging info.

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Peter Parente
Solved:
2010-02-19
Last query:
2010-02-19
Last reply:
2010-02-18
CompSciGuy (evanspielman) said : #1

This seems incredibly useful! Does anyone know of any way to get this to work on Windows platforms, as the "sikuli-script" jar file does not exist in the Windows version?

Peter Parente (parente) said : #2

We just figured out Windows today. I'll post how later tonight. It turns out you don't even need to replace the jar file on Mac or Windows.

Peter Parente (parente) said : #3

I updated the description above with details about how to make this work on both Mac and Windows.

YeTr2 (yetr2quared) said : #4

Now to figure out the setup for linux.

chimanfu (jfu) said : #5

suite = unittest.TestLoader().loadTestsFromTestCase(MyTests)
unittest.TextTestRunner(verbosity=2).run(suite)

that is to run the whole test suite. How to make it run on only 1 specific testcase if I have tons of testcases and don't want to do
def _test1_(self):

kmartino (kmartino) said : #6

Hello,

I am on Mac OSX Leppard and am getting this error outputted in test-output.log when attempting this:

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:676)
 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
 at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
 at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:317)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
 at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:375)

I'd love to use this same approach. Let me know if you can where to look for the issue and thanks for the assistence, this is a terrific help!

Karl

kmartino (kmartino) said : #7

Hi,

I wanted to report that I figured out my issue. Simply had to follow the instructions exactly and all was well.

Thanks for this great tip.

Karl

RaiMan (raimund-hocke) said : #8

Since this approach sounds very complicated, I tried with native means of Sikuli (version 0.9.9), to get basically the same results.
It works both on Mac 10.6 and Windows 7.

In the Sikuli IDE I coded the test suite, as mentioned above (only whats needed):

import unittest
setBundlePath("full path to your saved youNameIt.sikuli") # tells the Sikuli functions where to find the pictures
class MyTests(unittest.TestCase):
   def setUp(self):
      switchApp("Safari")
      # on Windows: e.g. switchApp("google"), to switch to a running Chrome Browser

   def tearDown(self):
      pass

   def testNewTab(self):
      type("t", KEY_CMD) # Win: KEY_CTRL (KEY_META gives Error)
      paste("https://answers.launchpad.net/sikuli/+question/100436") # this question ;-)
      type(Key.ENTER) # no errors with Key class in .skl
      m = find(<image>) # the captured Sikuli logo
      assert(m is not None and m.getScore() > 0.9)

suite = unittest.TestLoader().loadTestsFromTestCase(MyTests)
unittest.TextTestRunner(verbosity=2).run(suite)

If you now run this (normal run) in the IDE, it will run with success.

Now you save it as executable.

Windows:
I modified the Sikuli-IDE.bat (Sikuli program folder) by adding a pause at the end, so the cmd-window, that is started when double clicking on the .skl, stays open, so you can check the output. If you want to build your own cmd workflows, just call the bat with the .skl as parameter.

Mac:
In a terminal session I just used the java starter (Sikuli-IDE.app/Contents/MacOS/JavaApplicationStub) and gave it the .skl as parameter. The output is reported in the terminal session.

In both cases I did not have any problems, running these tests from the commandline.

I prefer this approach, so I use nearly everything as it comes with Sikuli and only care for the input and output (e.g. piping it to a file and do some post processing).

The only two things, you have to care for:
1. if you want to run tests from command line, you have to build the test suite on your own (no magic at all, +5 statements against the IDE approach), since an .skl will do nothing (only def()'s, it does not know, that its a test suite outside the IDE)
2. you have to tell, where the pictures reside (easiest way: use setBundlePath()).

RaiMan (raimund-hocke) said : #9

@ kmartino:
Since you have not subscribed to answer https://answers.launchpad.net/sikuli/+question/103782, I tell you at this place, that I have answered there, with a reference to this discussion ;-)

kmartino (kmartino) said : #10

Hi RaiMan,

Thanks for the reply.

That's fantastic and it worked for me.

Question: how come I can't get anything meaninful from sys.argv ?

For example I modified the code like so:

import unittest, sys
print('hi')
count = 1
for arg in sys.argv[1:]:
    print('Argument %i=%s' % (count, arg))
    count += 1
setBundlePath("/Users/kmarti05/Desktop/_lab_tests/example3.sikuli") # tells the Sikuli functions where to find the pictures
class MyTests(unittest.TestCase):
   def setUp(self):
      switchApp("Safari")

   def tearDown(self):
      pass

   def testNewTab(self):
      type("t", KEY_CMD) # Win: KEY_CTRL (KEY_META gives Error)
      paste("https://answers.launchpad.net/sikuli/+question/100436") # this question ;-)
      type(Key.ENTER) # no errors with Key class in .skl
      m = find( ) # the captured Sikuli logo
      assert(m is not None and m.getScore() > 0.9)

suite = unittest.TestLoader().loadTestsFromTestCase(MyTests)
unittest.TextTestRunner(verbosity=2).run(suite)

And attempt to run

$ /Applications/Sikuli-IDE.app/Contents/MacOS/JavaApplicationStub /Users/kmarti05/Desktop/_lab_tests/example3.skl test1 test2

test1 and test2 do not print.

Thanks,

Karl

PS - I need to send an email to the users email list - I recently participated in a research project where I work (Comcast Interactive Media) that went very well using Sikuli.

Thanks again,

Karl

RaiMan (raimund-hocke) said : #11

Thats very simple:

any arguments from a command line are not given thru to a Sikuli script.

The only solution is to read something from a file with one line, that has been prepared before calling the script.

using

myArgv = eval("[" + file("path to a file").readline() + "]")

would give you a list according to sys.argv, if the line would look like

1, 5.6, "a text", "more text", [ 5, 7, "text" ], "the last parm"

Have fun.

I am on Mac OS X 10.5.8 (Leopard), i tried the steps mentioned above for Mac

When i execute this (Java 1.6)

java -d32 -Dpython.path=Lib/ -jar sikuli-script.jar mytest.sikuli 2> test-output.log

I get the following error:

Cannot run Java in 32 bit mode. Continuing in 64 bit mode.
Exception in thread "main" Traceback (innermost last):
  File "<string>", line 1, in ?
  File "/Users/nachiket/Downloads/sikuli-script/sikuli-script.jar/Lib/python/edu/mit/csail/uid/Sikuli.py", line 11, in ?
 at java.lang.ClassLoader$NativeLibrary.load(Native Method)
 at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1861)
 at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1741)
 at java.lang.Runtime.load0(Runtime.java:770)
 at java.lang.System.load(System.java:1020)
 at com.wapmx.nativeutils.jniloader.NativeLoader.loadLibrary(NativeLoader.java:44)
 at edu.mit.csail.uid.VDictProxy.<clinit>(VDictProxy.java:18)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:169)
 at org.python.core.SyspathJavaLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
 at org.python.core.Py.findClassEx(Unknown Source)
 at org.python.core.SysPackageManager.findClass(Unknown Source)
 at org.python.core.PackageManager.findClass(Unknown Source)
 at org.python.core.SysPackageManager.findClass(Unknown Source)
 at org.python.core.PyJavaPackage.__findattr__(Unknown Source)
 at org.python.core.imp.importFromAs(Unknown Source)
 at org.python.core.imp.importFrom(Unknown Source)
 at python.edu.mit.csail.uid.Sikuli$py.f$0(/Users/nachiket/Downloads/sikuli-script/sikuli-script.jar/Lib/python/edu/mit/csail/uid/Sikuli.py:11)
 at python.edu.mit.csail.uid.Sikuli$py.call_function(/Users/nachiket/Downloads/sikuli-script/sikuli-script.jar/Lib/python/edu/mit/csail/uid/Sikuli.py)
 at org.python.core.PyTableCode.call(Unknown Source)
 at org.python.core.PyCode.call(Unknown Source)
 at org.python.core.imp.createFromCode(Unknown Source)
 at org.python.core.imp.createFromSource(Unknown Source)
 at org.python.core.ZipFileImporter$ZipFileLoader.load_module(Unknown Source)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
 at java.lang.reflect.Method.invoke(Method.java:597)

java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: /Users/nachiket/Downloads/sikuli-script/tmplib/libVDictProxy.jnilib: no suitable image found. Did find: /Users/nachiket/Downloads/sikuli-script/tmplib/libVDictProxy.jnilib: no matching architecture in universal wrapper

(I know this is because of the lack of 64 bit support in our binaries)

When i change my java to (1.5)
the get the error : bad verison in class file

So Now when i try on Windows:

I get the following error:

Exception in thread "main" Traceback (innermost last):
 (no code object) at line 0
SyntaxError: ('inconsistent dedent', ('C:\\sikuli-script\\sportstest.sikuli\\sportstest.py', 16, 2, ' switchApp("C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE")'))

My test file looks like :

import sys
import unittest

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

  def setUp(self):

switchApp("C:\Program Files\Internet Explorer\IEXPLORE.EXE")

   # @todo: do similar for IE on Windows

 def tearDown(self):

pass

 def testNewTab(self):

 type ("https://sports.yahoo.com\n")

m = find("sports-logo.png")

assert(m is not None and m.getScore() > 0.9)

suite = unittest.TestLoader().loadTestsFromTestCase(MyTests)

unittest.TextTestRunner(verbosity=2).run(suite)

My cygwin command prompt looks like this:

$ /cygdrive/c/Program\ Files/Java/jdk1.6.0_17/bin/java -Dpython.path=Lib/ -jar
sikuli-script.jar sportstest.sikuli 2> test-output.log
VDictProxy loaded.
ScreenMatchProxy loaded.
Win32Util loaded.

Please help me , i want to start using Sikuli in any unit test format.. asap.

RaiMan (raimund-hocke) said : #13

1. I think you should not use
java -d32 -Dpython.path=Lib/ -jar sikuli-script.jar mytest.sikuli 2> test-output.log
There is no need to do that this way. look at my comment from 29-03 "Since this approach sounds ....".
There are different Sikuli versions for OS X 10.5 and 10.6. So If you use the right version, my approach should work.

2. Since your script ran on Windows, it found the syntax error in your script: inconsistent dedent
This is something special (and a bit weird) with Python, that you have to know: indentation and dedentation to form a block of statements.
If you are using the IDE, you have to decide, wether to use the tab key or the spacebar to insert indentation. The tab key produces 3 blanks. Python checks indentation and dedentation to decide, to what block a statement belongs. So if you indent some block with e.g. 3 spaces, the next statement after the block has to be dedented by 3 spaces or even more to switch back to the correct level (e.g. "suite ..." as next statement after "class ..." has to be dedented by 6 spaces (or to the beginning of the line, since this is the level of the script). I'm sure, you will get used to it ;-)

Your script should look like this (I used 3 spaces to indent)

import unittest

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

   def setUp(self):
      switchApp("C:\Program Files\Internet Explorer\IEXPLORE.EXE")

   def tearDown(self):
      pass

   def testNewTab(self):
      type ("https://sports.yahoo.com\n")
      m = find("sports-logo.png")
      assert(m is not None and m.getScore() > 0.9)

suite = unittest.TestLoader().loadTestsFromTestCase(MyTests)
unittest.TextTestRunner(verbosity=2).run(suite)

RaiMan (raimund-hocke) said : #14

I want to add (to avoid frustration):

When using this approach (that gives you a chance to run a test suite as Sikuli executable), you have to care for the place of your pictures. Its documented (setBundlePath()) in my comment above.

RaiMan (raimund-hocke) said : #15

Sorry, one more thing:

with openApp()/switchApp() on Windows, you have to use double backslashes for the path.

switchApp("C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE")

Hi thank you , this works perfectly fine now.

Just one small things :

It opens up the browser (IE in my case) and then stays on about blank causing the tests to fail.. why is this happening?

When i open a browser (open the link that i want to open , sports.yahoo.com ) and run this it works perfectly: It actually does open another browser which is blank .. and my test passes. So basically i think there is some issue issue with opening and relating the browser , can u help?

RaiMan (raimund-hocke) said : #17

this works for me (see comments after the #). Have fun.

import unittest
setAutoWaitTimeout(5000)
setBundlePath("C:\\Users\\RaiMan\\Desktop\\testie.sikuli") # saved here from IDE before running the test

class MyTests(unittest.TestCase):
   def setUp(self):
      switchApp("C:\Program Files\Internet Explorer\IEXPLORE.EXE")
      sleep(3) # give IE some time to come up and get ready

   def tearDown(self):
      pass

   def testNewTab(self):
      paste("http://sports.yahoo.com") # I prefer to use paste, when typing text
      type(Key.ENTER)
      m = find() # here I just captured the logo, its found because of setBundlePath
      assert(m is not None and m.getScore() > 0.9)

suite = unittest.TestLoader().loadTestsFromTestCase(MyTests)
unittest.TextTestRunner(verbosity=2).run(suite)

Peter Parente (parente) said : #18

RaiMan's approach is indeed simpler than my original post. It does require use of the Sikuli IDE, however, to at least produce the executable.

I understand that the IDE is what the MIT group's research is all about. But what I'd really like to see in Sikuli is a separation between the library and IDE. It would be infinitely more useful if my Python / Jython script could "import sikuli" and start using its functions instead of having Sikuli import my scripts to run. Of course, the IDE can still follow the latter approach, but the former would make use of Sikuli much cleaner in other contexts.

RaiMan (raimund-hocke) said : #19

gorgious idea: being able to import sikuli functionality into a python script. I agree, that this is something that they should think about in the long run. In the moment they are busy with the functionality at all and the usability. Version 0.10 will be a big step.

With your suggestion, its possible to first develop the test in the IDE, and then add the 5 "frame" statements and you can save and run it as executable. the only thing you have to take care for, is to not use the Sikuli assert's.

When trying to evaluate my approach, I was motivated by some requests, where it was obvious, that these people did not know anything about python. they just wanted to run a test as executable, that works fine in the IDE.

Cies Breijs (cies) said : #20

@Peter Parente: i agree separation of IDE and library would be very welcome!

and thanks for posing this.. i really needed it :)

i have 2 simple scripts now, run_test.bat:
@echo off
PATH=%PATH%;.\win32
java -Dpython.path=lib/sikuli/Lib/ -jar lib/sikuli/sikuli-script.jar %* 2>> test.log

and run_all.bat:
FOR /D %F IN ("*.sikuli") DO run_test %F

the results are added to the test.log file. my colleagues can still use the sikuli IDE to make the tests, that's great. a great speedup would be to write a little java/python that just executes all the sikuli tests it can find recursively on a given path. that would speed it up a lot (java is quite fast once it runs). but for now im happy.

on the mailing list i mention about my need, and my wish for a separate lib/ide:
https://lists.csail.mit.edu/pipermail/sikuli-users/2010-April/thread.html
sean says the separate lib is basically the sikuli-script.jar in the sikuli-ide-full.jar

Cies Breijs (cies) said : #21

i have modified the sikuli-script.jar so the method edu.mit.csail.uid.SikuliScript.main now contains:

if (args.length == 0 ) {
  System.out.println("Usage: sikuli-script [list of .sikuli directories]");
  return;
}
for (int i = 0; i < args.length; i++) {
  // it will try every script is receives, continuing with the rest if one fails
  try {
    ScriptRunner runner = new ScriptRunner();
    runner.runPython(args[i]);
  }
  catch(IOException e) {
    e.printStackTrace();
  }
}

with this minor change it can now run multiple sikuli scripts consecutively within the same JVM process. (before i had to start a JVM for each test, slowing down the test suite a lot)

my batch file, run_tests.bat, looks like:

@echo off
PATH=%PATH%;.\lib\sikuli\win32
java -Dpython.path=lib/sikuli/Lib/ -jar lib/sikuli/sikuli-script.jar %* 2>> test.log

the tree looks like:

+---lib
| \---sikuli
| +---Lib
| +---tmplib
| \---win32
+---mytest.sikuli
+---mytest2.sikuli
\---tmplib

with my run_tests.bat and the test.log in the root. the lib/sikuli dir contains the sikuli-script.jar.
this sikuli-script.jar is treated with my patch (copyied the SikuliScript.java from the bazaar trunk, modified it and compiled it with javac, copied the resulting class file back into the jar).

now i can do:
run_tests.bat mytest.sikuli mytest2.sikuli

and they are run from the same JVM instance.

i will submit this patch to the sikuli devs.

cheers,
cies breijs.

Peter Parente (parente) said : #22

@Cies Breijs: What I really meant by separation of IDE from library is that I'd love to be able to write my own Jython script "foobar.py" with content:

import sikuli
# other imports

m = sikuli.find('something.png')
# other stuff

and run it as:

jython foobar.py

In other words, it would be great if Sikuli was it's own module, just like any other Jython module. Having sikuli-script.jar run my scripts seems very backwards for something is supposed to be a library.

Cies Breijs (cies) said : #23

@Peter:

i could not agree more. i would even like to see the java side of the lib to be a separate component. the jython wrapper over the java-originated functionality is not that much. if there is a separate base lib with a _very_ stable API, we could easily make many implementations for many languages. (JRuby, or regular ruby with a java bridge -- i just love to use ruby for testing)

but for now im happy. i also had a requirement of being able to use the sikuli IDE for making tests; this because my colleagues are no long time programmers, and i would not know how to make all those screenshots without the IDE.

RaiMan (raimund-hocke) said : #24

May be this helps (not yet really documented, information from developer):

---------------
(1) The steps to use Sikuli.py without Sikuli IDE:
 1. add sikuli-script.jar into Java's CLASSPATH
 2. add -Dpython.home=sikuli-script.jar as a parameter of launching java
 3. add "from python.edu.mit.csail.uid.Sikuli import *" in your python code. (Note that the package name will be changed in 0.10.)

(2)
Sikuli need some opencv libraries in tmplib/.
Try to add tmplib/ to %PATH% before running Jython.

(3)
In theory, you can import the other xxx.sikuli/xxx.py and call its functions. A tricky step is that you need to call setBundlePath() before using the image files inside the other .sikuli bundle, otherwise Sikuli's functions doesn't know where to find the images.
We will try to make this easier in the future versions.
-----------------

sjohnson (sjohnson-bbook) said : #25

@Peter: Were you able to set this up the same way using sikuli 0.10?

Libo Cao (libocao) said : #26

How to include the sikuli 0.10 library in python?

The old
"from python.edu.mit.csail.uid.Sikuli import *" does not work with 0.10 any more, since Raiman mentioned it will change in 0.10

I tried
from sikuli/Sikuli import *

and it does not work.

Libo Cao (libocao) said : #27

How to include the sikuli 0.10 library in python?

The old
"from python.edu.mit.csail.uid.Sikuli import *" does not work with 0.10 any more, since Raiman mentioned it will change in 0.10

I tried
from sikuli/Sikuli import *

and it does not work.

RaiMan (raimund-hocke) said : #28

I guess looking at
https://answers.launchpad.net/sikuli/+question/108782
may help you to get it working again.

Libo Cao (libocao) said : #29

RaiMan,

It still does not work after the upgrade. modified the include to be "import sikuli.Sikuli.* "

when running in command mode, still having exceptions (note that all my testsuites runs fine in command line mode before upgrading to sikuli 1.0). Now I am having exceptions like:

Exception in thread "main" Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "../../Sikuli-Mac-Lib_1.0/Lib/sikuli/Sikuli.py", line 165, in <module>
    initSikuli()
  File "../../Sikuli-Mac-Lib_1.0/Lib/sikuli/Sikuli.py", line 160, in initSikuli
    __main__.SCREEN = Screen()
  File "../../Sikuli-Mac-Lib_1.0/Lib/sikuli/Screen.py", line 15, in __init__
    r = JScreen().getBounds()
 at edu.mit.csail.uid.EventManager.createEventManager(Native Method)
 at edu.mit.csail.uid.EventManager.<init>(EventManager.java:37)
 at edu.mit.csail.uid.Region.init(Region.java:55)
 at edu.mit.csail.uid.Screen.initBounds(Screen.java:79)
 at edu.mit.csail.uid.Screen.<init>(Screen.java:93)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
 at org.python.core.PyReflectedConstructor.constructProxy(PyReflectedConstructor.java:163)

java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: edu.mit.csail.uid.EventManager.createEventManager()J

Libo Cao (libocao) said : #30

I am running commandline mode on a mac.

Info: tmplib no problem, python path set, sikuli-script.jar added to path, and all testsuites runs smoothly before 1.0 upgrade. Now I am just not sure which version to downgrade to.

Tsung-Hsiang Chang (vgod) said : #31

@libo: Remove the tmplib/ entirely. It looks like you are using the old jnilibs.

Libo Cao (libocao) said : #32

@chang,

I removed the tmplib, but new ones does not generate automatically, only with one file libScreenMatchProxy.jnilib generated automatically, how do you regenerate the tmplib successfully?
*************************************************************************************

Exception in thread "main" Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Sikuli-Mac-Lib_1.0/sikuli-script.jar/Lib/sikuli/Sikuli.py", line 18, in <module>
java.lang.UnsatisfiedLinkError: /mac_BAT/tmplib/libScreenMatchProxy.jnilib: Library not loaded: /opt/local/lib/libcv.4.dylib Referenced from: /mac_BAT/tmplib/libScreenMatchProxy.jnilib Reason: image not found
 at java.lang.ClassLoader$NativeLibrary.load(Native Method)
 at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1861)
 at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1741)
 at java.lang.Runtime.load0(Runtime.java:770)
 at java.lang.System.load(System.java:1020)
 at com.wapmx.nativeutils.jniloader.NativeLoader.loadLibrary(NativeLoader.java:44)
 at edu.mit.csail.uid.Finder.<clinit>(Finder.java:16)
 at java.lang.Class.forName0(Native Method)
 at java.lang.Class.forName(Class.java:169)
 at org.python.core.SyspathJavaLoader.loadClass(SyspathJavaLoader.java:107)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
 at org.python.core.Py.findClassEx(Py.java:817)
 at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:133)
 at org.python.core.packagecache.PackageManager.findClass(PackageManager.java:28)
 at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:122)
 at org.python.core.PyJavaPackage.__findattr_ex__(PyJavaPackage.java:137)
 at org.python.core.PyObject.__findattr__(PyObject.java:869)
 at org.python.core.imp.import_name(imp.java:771)
 at org.python.core.imp.importName(imp.java:806)
 at org.python.core.ImportFunction.__call__(__builtin__.java:1232)
 at org.python.core.PyObject.__call__(PyObject.java:367)
 at org.python.core.__builtin__.__import__(__builtin__.java:1202)
 at org.python.core.imp.importFromAs(imp.java:884)
 at org.python.core.imp.importFrom(imp.java:860)
 at sikuli.Sikuli$py.f$0(/Users/amitp/liboc/CATS/trunk/client_automation/Sikuli-Mac-Lib_1.0/sikuli-script.jar/Lib/sikuli/Sikuli.py:165)
 at sikuli.Sikuli$py.call_function(/Users/amitp/liboc/CATS/trunk/client_automation/Sikuli-Mac-Lib_1.0/sikuli-script.jar/Lib/sikuli/Sikuli.py)
 at org.python.core.PyTableCode.call(PyTableCode.java:165)
 at org.python.core.PyCode.call(PyCode.java:18)
 at org.python.core.imp.createFromCode(imp.java:326)
 at org.python.core.util.importer.importer_load_module(importer.java:109)
 at org.python.modules.zipimport.zipimporter.zipimporter_load_module(zipimporter.java:161)
 at org.python.modules.zipimport.zipimporter$zipimporter_load_module_exposer.__call__(Unknown Source)
 at org.python.core.PyBuiltinMethodNarrow.__call__(PyBuiltinMethodNarrow.java:47)
 at org.python.core.imp.loadFromLoader(imp.java:451)
 at org.python.core.imp.find_module(imp.java:408)
 at org.python.core.PyModule.impAttr(PyModule.java:109)
 at org.python.core.imp.import_next(imp.java:637)
 at org.python.core.imp.import_logic(imp.java:699)
 at org.python.core.imp.import_name(imp.java:761)
 at org.python.core.imp.importName(imp.java:806)
 at org.python.core.ImportFunction.__call__(__builtin__.java:1232)
 at org.python.core.PyObject.__call__(PyObject.java:367)
 at org.python.core.__builtin__.__import__(__builtin__.java:1202)
 at org.python.core.__builtin__.__import__(__builtin__.java:1185)
 at org.python.core.imp.importAll(imp.java:904)
 at org.python.pycode._pyx2.f$0(<string>:1)
 at org.python.pycode._pyx2.call_function(<string>)
 at org.python.core.PyTableCode.call(PyTableCode.java:165)
 at org.python.core.PyCode.call(PyCode.java:18)
 at org.python.core.Py.runCode(Py.java:1204)
 at org.python.core.Py.exec(Py.java:1248)
 at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:172)
 at edu.mit.csail.uid.ScriptRunner.runPython(ScriptRunner.java:52)
 at edu.mit.csail.uid.ScriptRunner.runPython(ScriptRunner.java:81)
 at edu.mit.csail.uid.SikuliScript.main(SikuliScript.java:76)

java.lang.UnsatisfiedLinkError: java.lang.UnsatisfiedLinkError: /mac_BAT/tmplib/libScreenMatchProxy.jnilib: Library not loaded: /opt/local/lib/libcv.4.dylib Referenced from: /mac_BAT/tmplib/libScreenMatchProxy.jnilib Reason: image not found

Libo Cao (libocao) said : #33

Also I was following the original method of this post to get it working with other version of Sikuli.

I needed to build a rather large system, which means it cannot run inside IDE, my system contains testsuite folders that only contains simple test cases, from those testsuites, it includes other python libraries, which import sikuli.Sikuli.* to build methods that could be used for all test cases. All the images needed are also inside an image library folder and defined in a python file, in that case, if any image changes, I do not need to update hundreds of test cases.

The whole system is triggered by BAT script that contains command lines like this:

java -d32 -Dpython.home=Sikuli-Mac-Lib_1.0/sikuli-script.jar -jar Sikuli-Mac-Lib_1.0/sikuli-script.jar ../TestSuites/maptest.sikuli

also tried:
java -d32 -Dpython.path=Sikuli-Mac-Lib_1.0/Lib/ -jar Sikuli-Mac-Lib_1.0/sikuli-script.jar ../TestSuites/maptest.sikuli \\

I know my current problem is to have the right tmplib, however it is not automatically generated right.

Tsung-Hsiang Chang (vgod) said : #34

@libo: You can install opencv using darwin ports, or use install_name_tool to change the path to *.dylib.
See Andrzej Wiech's comment on 2010-05-11: https://answers.launchpad.net/sikuli/+question/108878

Libo Cao (libocao) said : #35

Thanks Chang, it looks pretty complicated, I will give it a try and update here.

BTW, running command line mode should be properly documented on Sikuli page, now there is not a command line tool to download any more. in order to build a decent large automated system, command line method is the only method to go, so that hundreds of test case/automation tasks can be run via crontab mode.

Thanks a lot
Libo

Tsung-Hsiang Chang (vgod) said : #36

@libo:
Right, we should have a better document for running in command line.

Btw, actually there is an easy way to run Sikuli-IDE.app in commandline.
Try this: open -a /Applications/Sikuli-IDE.app xxx.skl

Libo Cao (libocao) said : #37

Thanks Chang,

I read this method from one of your old post, however it was not good for me, the reason is that you have to use sikuli IDE to generate those *.skl files, this is not scalable. For the hundreds of testsuites you build, you need to convert hundreds of times to generate those skl files. Especially you have to do this exporting to skl file even if you just added a few lines to an existing testsuites.

Instead using the other method, you can call directly any testsuite without the conversion step.

Tsung-Hsiang Chang (vgod) said : #38

@libo:

Well, in fact, .skl files can be easily converted from .sikuli/ folders using zip.
xxx.skl are just a simple zip of all the files in xxx.sikuli.
So you can simply put a line of "zip -uj xxx.skl xxx.sikuli/*" in your shell script before open.
zip -u can make it only update the changed or new files. It's fast, and can be done fully automatically.

However, I think I will add an command line option to run .sikuli directly, so you don't need to generate a .skl every time.

Libo Cao (libocao) said : #39

O, that makes sense, and it is totally easier to run that way. I did not know that until now :-) I wish I know Sikuli enough to contribute to a general How-to page. Just getting to know the project.

Tsung-Hsiang Chang (vgod) said : #40

@libo:

It's obvious we don't have enough people to write documents. :) There are too many secrets only in my head.
It would be great if you can write down your experience. I will be happy to collect and put them on Sikuli's official web site.

Libo Cao (libocao) said : #41

I will definitely do some documentation after I figure out this library issue I kept having after upgrading to Sikuli 0.10.0, now still struggling to get it working. I built a pretty large testing system using sikuli 0.9 version and it runs smoothly, now I had to update a lot of things to get the new feature from 0.10.0, for example only with 0.10.0 I can do iphone multi-touch feature testings.

Libo Cao (libocao) said : #42

Great, this method still works perfectly for windows XP using sikuli 0.10.1

Janet (wangyupep) said : #43

I had a problem when running tests in linux (Ubuntu10.04).
I had wrote a test scipt based on Python's unittest, and the program as follow:

import unittest
class TestTxtContent(unittest.TestCase):
    def setUp(self): #doubleclick open a text
     doubleClick("text image")
     sleep(1)

    def tearDown(self): #close the text
     click("close button")

    def test_content(self): #find that is there "hello" word in this test
        m = find("hello")
        assert(m is not None and m.getScore() > 0.9)

suite = unittest.TestLoader().loadTestsFromTestCase(TestTxtContent)
unittest.TextTestRunner(verbosity=2).run(suite)

I saved this program as TestTxtContent.sikuli.
I had run this script successfully in windowXP with command:
              java -Dpython.path=Lib/ -jar sikuli-script.jar TestTxtContent.sikuli 2> test-output.log
      the content of test_output.log:
          test_content (__main__.TestTxtContent) ... ok
          ----------------------------------------------------------------------
          Ran 1 tests in 6.188s

I rewrote this program in linux, and still use the command line in terminal. But it did not run succefully.
      the content of test_output.log:
          Ran 0 tests in 0.000s
          ----------------------------------------------------------------------

          OK
It seemed like the script did not run at all.
Why does this happen?

Janet (wangyupep) said : #44

I had a problem when running tests in linux (Ubuntu10.04).
I had wrote a test scipt based on Python's unittest, and the program as follow:

import unittest
class TestTxtContent(unittest.TestCase):
    def setUp(self): #doubleclick open a text
     doubleClick("text image")
     sleep(1)

    def tearDown(self): #close the text
     click("close button")

    def test_content(self): #find that is there "hello" word in this test
        m = find("hello")
        assert(m is not None and m.getScore() > 0.9)

suite = unittest.TestLoader().loadTestsFromTestCase(TestTxtContent)
unittest.TextTestRunner(verbosity=2).run(suite)

I saved this program as TestTxtContent.sikuli.
I had run this script successfully in windowXP with command:
              java -Dpython.path=Lib/ -jar sikuli-script.jar TestTxtContent.sikuli 2> test-output.log
      the content of test_output.log:
          test_content (__main__.TestTxtContent) ... ok
          ----------------------------------------------------------------------
          Ran 1 tests in 6.188s

I rewrote this program in linux, and still use the command line in terminal. But it did not run succefully.
      the content of test_output.log:
          Ran 0 tests in 0.000s
          ----------------------------------------------------------------------

          OK
It seemed like the script did not run at all.
Why does this happen?

Janet (wangyupep) said : #45

I had a problem when running tests in linux (Ubuntu10.04).
I had wrote a test scipt based on Python's unittest, and the program as follow:

import unittest
class TestTxtContent(unittest.TestCase):
    def setUp(self): #doubleclick open a text
     doubleClick("text image")
     sleep(1)

    def tearDown(self): #close the text
     click("close button")

    def test_content(self): #find that is there "hello" word in this test
        m = find("hello")
        assert(m is not None and m.getScore() > 0.9)

suite = unittest.TestLoader().loadTestsFromTestCase(TestTxtContent)
unittest.TextTestRunner(verbosity=2).run(suite)

I saved this program as TestTxtContent.sikuli.
I had run this script successfully in windowXP with command:
              java -Dpython.path=Lib/ -jar sikuli-script.jar TestTxtContent.sikuli 2> test-output.log
      the content of test_output.log:
          test_content (__main__.TestTxtContent) ... ok
          ----------------------------------------------------------------------
          Ran 1 tests in 6.188s

I rewrote this program in linux, and still use the command line in terminal. But it did not run succefully.
      the content of test_output.log:
          Ran 0 tests in 0.000s
          ----------------------------------------------------------------------

          OK
It seemed like the script did not run at all.
Why does this happen?

Janet (wangyupep) said : #46

I had a problem when running tests in linux (Ubuntu10.04).
I had wrote a test scipt based on Python's unittest, and the program as follow:

import unittest
class TestTxtContent(unittest.TestCase):
    def setUp(self): #doubleclick open a text
     doubleClick("text image")
     sleep(1)

    def tearDown(self): #close the text
     click("close button")

    def test_content(self): #find that is there "hello" word in this test
        m = find("hello")
        assert(m is not None and m.getScore() > 0.9)

suite = unittest.TestLoader().loadTestsFromTestCase(TestTxtContent)
unittest.TextTestRunner(verbosity=2).run(suite)

I saved this program as TestTxtContent.sikuli.
I had run this script successfully in windowXP with command:
              java -Dpython.path=Lib/ -jar sikuli-script.jar TestTxtContent.sikuli 2> test-output.log
      the content of test_output.log:
          test_content (__main__.TestTxtContent) ... ok
          ----------------------------------------------------------------------
          Ran 1 tests in 6.188s

I rewrote this program in linux, and still use the command line in terminal. But it did not run succefully.
      the content of test_output.log:
          Ran 0 tests in 0.000s
          ----------------------------------------------------------------------

          OK
It seemed like the script did not run at all.
Why does this happen?

Janet (wangyupep) said : #47

I am sorry....... I did not mean to add the same comment..... -_-!

Hi I need help with saving the the sikuli script on windows XP and Executing the same script O am uisng version 0.10.1 of Sikuli.
Any help would be really appericiated

Thanks