Robot Framework Problem

Asked by Peter Kim

Hi.

I followed the instructions on http://blog.mykhailo.com/2011/02/how-to-sikuli-and-robot-framework.html but am having some problems with Robot Framework.

Here is the information on my system:
- Windows XP Service Pack 3
- Java Runtime Environment (JRE 6_27)
- Jython 2.5.2
- Python 2.7.2
- Robot Framework 2.5.5
- Sikuli X 1.0rc3

My robottest.bat looks like the following:
@echo off
set sikuli_jar=D:\Program Files\Sikuli X\sikuli-script.jar
java -cp "robotframework-2.5.5.jar;%sikuli_jar%" ^
     -Dpython.path=..\robotframework-2.5.5.jar\Lib;"%sikuli_jar%/Lib" ^
     org.robotframework.RobotFramework ^
     --pythonpath=calc.sikuli ^
     --outputdir=results ^
     --loglevel=TRACE ^
     %*

When I run it, I get following message:
D:\Sikuli\RobotFramework> robottest.bat robot_suite\verify_operations.txt
Exception in thread "main" Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "D:\Sikuli\RobotFramework\robotframework-2.5.5.jar\Lib\robot\__init__$py.class", line 16, in <module>
  File "D:\Program Files\Sikuli X\sikuli-script.jar\Lib\os.py", line 118, in <module>
ImportError: no os specific module found

I run test using jybot.bat, which looks like following:
@echo off
set sikuli_jar=D:\Program Files\Sikuli X\sikuli-script.jar
set CLASSPATH=%sikuli_jar%
set JYTHONPATH=%sikuli_jar%/Lib
jybot --pythonpath=calc.sikuli ^
      --outputdir=results ^
      --loglevel=TRACE ^
      %*

I get the following message:
D:\Sikuli\RobotFramework>jybottest.bat robot_suite\verify_operations.txt

[ ERROR ] Invalid syntax in file 'd:\sikuli\robotframework\robot_suite\verify_operations.txt' in table 'Settings':
Importing test library 'calc.Calculator' failed:
SyntaxError: 'with' will become a reserved keyword in Python 2.6 (calc.py, line 37)
PYTHONPATH: [u'calc.sikuli', 'D:\\Python27\\Lib\\site-packages', 'D:\\Python27\\Lib\\site-packages\\robot\\libraries','D:\\Program Files\\Sikuli X\\sikuli-script.jar\\Lib', 'D:\\jython2.5.2\\Lib', '__classpath__','__pyclasspath__/', 'D:\\jython2.5.2\\Lib\\site-packages', '.']
CLASSPATH: D:\jython2.5.2\jython.jar;D:\Program Files\Sikuli X\sikuli-script.jar

Traceback (most recent call last):
  File "D:\Python27\Lib\site-packages\robot\utils\importing.py", line 88, in _import
    imported = __import__(modname, {}, {}, fromlist)
  File "D:\Python27\Lib\site-packages\robot\utils\importing.py", line 88, in _import
    imported = __import__(modname, {}, {}, fromlist)
==============================================================================
Verify Operations
==============================================================================
Verify that 2 + 2 = 4 | FAIL |
No keyword with name 'Start App' found.
------------------------------------------------------------------------------
Verify that 2 + 2 = 5 | FAIL |
No keyword with name 'Start App' found.
------------------------------------------------------------------------------
Verify Operations | FAIL |
2 critical tests, 0 passed, 2 failed
2 tests total, 0 passed, 2 failed
==============================================================================
Output: d:\sikuli\robotframework\results\output.xml
Report: d:\sikuli\robotframework\results\report.html
Log: d:\sikuli\robotframework\results\log.html

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Peter Kim
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

--- first case
possible mix up of Jython versions??
- rc3 for Windows still contains Jython 2.5.1 (which you reference by %sikuli_jar%/Lib)

--- second case
possible mix up of Python and Jython
D:\Python27\Lib\site-packages\robot\utils\importing.py
- there should not be any Python involved, Sikuli can only be run with Jython

Revision history for this message
RaiMan (raimund-hocke) said :
#2
Revision history for this message
Peter Kim (pd-kim) said :
#3

Hi RaiMan,

I uninstalled Jython 2.5.2, Python 2.7.2, Robot Framework 2.5.5, and Sikuli X 1.0rc3 and reinstalled Jython 2.5.1 and Sikuli X 1.0rc3. I then downloaded robotframework-2.5.5.jar.

However I still have the same problem:

D:\Sikuli\RobotFramework>robottest.bat robot_suite\verify_operations.txt
Exception in thread "main" Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "D:\Sikuli\RobotFramework\robotframework-2.5.5.jar\Lib\robot\__init__$py.class", line 16, in <module>
  File "D:\Program Files\Sikuli X\sikuli-script.jar\Lib\os.py", line 118, in <module>
ImportError: no os specific module found

My robottest.bat looks like the following:

@echo off
set sikuli_jar=D:\Program Files\Sikuli X\sikuli-script.jar
java -cp "robotframework-2.5.5.jar;%sikuli_jar%" ^
     -Dpython.path=..\robotframework-2.5.5.jar\Lib;"%sikuli_jar%/Lib" ^
     org.robotframework.RobotFramework ^
     --pythonpath=calc.sikuli ^
     --outputdir=results ^
     --loglevel=TRACE ^
     %*

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

looking at the docs of RFW, I would make the bat this way:

@echo off
set sikuli_jar=D:\Program Files\Sikuli X\sikuli-script.jar
java -cp "%sikuli_jar%" ^
    -jar robotframework-2.5.5.jar ^
     --pythonpath="%sikuli_jar%/Lib";calc.sikuli ^
     --outputdir=results ^
     --loglevel=TRACE ^
     %*

which is the recommended way, to start RFW, using the standalone jar.
-cp and --pythonpath should just add things needed by Sikuli to the end of the appropriate path's

BTW: I did not find 2.5.5.jar downloadable, the latest 2.5 version is 2.5.7

Revision history for this message
Peter Kim (pd-kim) said :
#5

RaiMan,

I used the new bat file and got a different error this time:

D:\Sikuli\RobotFramework>robottest.bat robot_suite\verify_operations.txt
[ ERROR ] Invalid syntax in file 'd:\sikuli\robotframework\robot_suite\verify_op
erations.txt' in table 'Settings': Importing test library 'calc.Calculator' fail
ed: ImportError: No module named calc
PYTHONPATH: ['D:\\Sikuli\\RobotFramework\\robotframework-2.5.5.jar\\Lib\\robot\\
libraries', 'D:\\Sikuli\\RobotFramework\\Lib', 'D:\\Sikuli\\RobotFramework\\robo
tframework-2.5.5.jar\\Lib', '__classpath__', '__pyclasspath__/', '.']
CLASSPATH: robotframework-2.5.5.jar
Traceback (most recent call last):
  File "D:\Sikuli\RobotFramework\robotframework-2.5.5.jar\Lib\robot\utils\import
ing$py.class", line 94, in _import
==============================================================================
Verify Operations
==============================================================================
Verify that 2 + 2 = 4 | FAIL |
No keyword with name 'Start App' found.
------------------------------------------------------------------------------
Verify that 2 + 2 = 5 | FAIL |
No keyword with name 'Start App' found.
------------------------------------------------------------------------------
Verify Operations | FAIL |
2 critical tests, 0 passed, 2 failed
2 tests total, 0 passed, 2 failed
==============================================================================
Output: d:\sikuli\robotframework\results\output.xml
Report: d:\sikuli\robotframework\results\report.html
Log: d:\sikuli\robotframework\results\log.html

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

Ok, the option --pythonpath seems not yet being processed at time of error, since they are not appended to the PYTHONPATH.

so you might try this one:

@echo off
set sikuli_jar=D:\Program Files\Sikuli X\sikuli-script.jar
java -cp "%sikuli_jar%" ^
    -Dpython.path=<absoluete-path-to>calc.sikuli ^
    -jar robotframework-2.5.5.jar ^
     --outputdir=results ^
     --loglevel=TRACE ^
     %*

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

If this comes up with the error, that module sikuli cannot be found (as a result of the "from sikuli import *" in calc.sikuli), you should then add "%sikuli_jar%/Lib" to -Dpython.path, and see what happens.

BTW: how did you tell calc.py, where to find the images? Since you are just processing the calc.py with plain Jython, the image path is not set.

Revision history for this message
Peter Kim (pd-kim) said :
#8

RaiMan,

I changed robottest.bat as following:

@echo off
set sikuli_jar=D:\Program Files\Sikuli X\sikuli-script.jar
java -cp "%sikuli_jar%" ^
    -Dpython.path=<absoluete-path-to>calc.sikuli ^
    -jar robotframework-2.5.5.jar ^
     --outputdir=results ^
     --loglevel=TRACE ^
     %*

I then got following error messages:

D:\Sikuli\RobotFramework>robottest.bat robot_suite\verify_operations.txt
[ ERROR ] Invalid syntax in file 'd:\sikuli\robotframework\robot_suite\verify_operations.txt' in table 'Settings': Importing test library 'calc.Calculator' failed: ImportError: No module named sikuli
PYTHONPATH: ['D:\\Sikuli\\RobotFramework\\robotframework-2.5.5.jar\\Lib\\robot\\libraries','D:\\Sikuli\\RobotFramework\\calc.sikuli', 'D:\\Sikuli\\RobotFramework\\Lib','D:\\Sikuli\\RobotFramework\\robotframework-2.5.5.jar\\Lib', '__classpath__', '__pyclasspath__/', '.']
CLASSPATH: robotframework-2.5.5.jar
Traceback (most recent call last):
  File "D:\Sikuli\RobotFramework\robotframework-2.5.5.jar\Lib\robot\utils\importing$py.class", line 94, in _import
  File "D:\Sikuli\RobotFramework\calc.sikuli\calc.py", line 2, in <module>
    from sikuli.Sikuli import *
  File "D:\Sikuli\RobotFramework\Lib\sikuli\__init__.py", line 3, in <module>
    from Sikuli import *
  File "D:\Sikuli\RobotFramework\Lib\sikuli\Sikuli.py", line 10, in <module>
    from org.sikuli.script import SikuliScript

I then added "%sikuli_jar%/Lib" to -Dpython.path. robottest.bat looked like following:

@echo off
set sikuli_jar=D:\Program Files\Sikuli X\sikuli-script.jar
java -cp "%sikuli_jar%" ^
    -Dpython.path=D:\Sikuli\RobotFramework\calc.sikuli;"%sikuli_jar%/Lib" ^
    -jar robotframework-2.5.5.jar ^
     --outputdir=results ^
     --loglevel=TRACE ^
     %*

I then received the following error message:

D:\Sikuli\RobotFramework>robottest.bat robot_suite\verify_operations.txt
Exception in thread "main" Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "D:\Sikuli\RobotFramework\robotframework-2.5.5.jar\Lib\robot\__init__$py.class", line 16, in <module>
  File "D:\Program Files\Sikuli X\sikuli-script.jar\Lib\os.py", line 118, in <module>
ImportError: no os specific module found

Here is calc.py:

from __future__ import with_statement
from sikuli.Sikuli import *

class Calculator(object):

 def __init__(self):
  self.appCoordinates = (0, 0, 1024, 768)

 def startApp(self):
  calcApp = App.open("calc.exe"); wait(2)
  calcApp.focus(); wait(1)

 def verifyApp(self):
  # check application
  if exists("calculator.png"):
   print("PASS: Calculator window appeared")
  else:
   print("FAIL: No calculator window")

 def performAction(self, *args):
  # get application region
  find("calculator.png")
  match = getLastMatch()
  self.appCoordinates = (match.getX(), match.getY(), match.getW(), match.getH())
  appRegion = Region(*self.appCoordinates)

  #rewrite action
  action = args[1]
  if args[1] == '+':
   action = 'Plus'
  elif args[1] == 'exp':
   action = 'Exp'

  with appRegion:
   Settings.MinSimilarity = 0.99
   click("btnC.png")
   click( "btn%s.png" % (args[0],) )
   click( "btn%s.png" % (action,) )
   click( "btn%s.png" % (args[2],) )
   click("btnEqual.png")
   Settings.MinSimilarity = 0.70

 def verifyResult(self, *args):
  expected_result = str(eval(''.join(args)))
  actual_result = self.getResultFromClipboard()

  #verification
  if actual_result == expected_result:
   print("PASS: Action performed correctly and result equals %s" % expected_result)
  else:
   print("FAIL: Actual result '%s' is not equal to expected result '%s'" % (actual_result, expected_result))

 def getResultFromClipboard(self):
  type('c', KEY_CTRL)
  return str(Env.getClipboard())

 def runTest(self):
  self.startApp()
  self.verifyApp()

  actions = '2+2'
  self.performAction(*actions)
  self.verifyResult(*actions)

if __name__ == "__main__":
 calc = Calculator()
 calc.runTest()

#"btn2.png"
#"btnEqual.png"
#"btnC.png"
#"btnPlus.png"
#"btnMinus.png"

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

Ok, according Python, the first one in comment #8 is the correct one:
It finds the module imported with
from sikuli import *

but the problem is during Sikuli init:
from org.sikuli.script import SikuliScript

and this is Java code, that cannot be found, because sikuli-script.jar is not in the class path:
CLASSPATH: robotframework-2.5.5.jar

though we used
set sikuli_jar=D:\Program Files\Sikuli X\sikuli-script.jar
java -cp "%sikuli_jar%" ^

So you have to find out, how to get sikuli-script.jar into the class path of RFW

Revision history for this message
Peter Kim (pd-kim) said :
#10

RaiMan,

The last time I wrote or debugged code was about 20 years ago but Sikuli makes me happy to write simple Jython scripts.
I did not know how to find out how to get sikuli-script.jar into the class path of RFW.

I installed Sikuli X-1.0rc2.

Using the original bat file from the Mike's cognition blog,
my robottest.bat looked like the following:

@echo off

set sikuli_jar=D:\Program Files\Sikuli X\sikuli-script.jar

java -cp "robotframework-2.5.5.jar;%sikuli_jar%" ^
     -Dpython.path="%sikuli_jar%/Lib" ^
     org.robotframework.RobotFramework ^
     --pythonpath=calc.sikuli ^
     --outputdir=results ^
     --loglevel=TRACE ^

This time it almost worked; there was no error message.
However the test case 2 + 2 = 5 showed that it passed.

D:\Sikuli\RobotFramework>robottest.bat robot_suite\verify_operations.txt
[info] Sikuli vision engine loaded.
[info] Windows utilities loaded.
[info] VDictProxy loaded.
==============================================================================
Verify Operations
==============================================================================
Verify that 2 + 2 = 4 | PASS |
------------------------------------------------------------------------------
Verify that 2 + 2 = 5 | PASS |
------------------------------------------------------------------------------
Click on non-existent button "Exp" | FAIL |
FindFailed: can not find btnExp.png
------------------------------------------------------------------------------
Verify Operations | FAIL |
3 critical tests, 2 passed, 1 failed
3 tests total, 2 passed, 1 failed
==============================================================================
Output: d:\sikuli\robotframework\results\output.xml
Report: d:\sikuli\robotframework\results\report.html
Log: d:\sikuli\robotframework\results\log.html

I tried robotframework-2.5.7.jar and 2.6.3.jar but it still could not show that the case 2 + 2 = 5 was FAIL.

So with Sikuli X-1.0rc2, robotframework almost worked on a Windows XP SP3 PC.

Revision history for this message
Peter Kim (pd-kim) said :
#11

Using Sikuli X-1.0rc2, I was able to follow the instructions on http://blog.mykhailo.com/2011/02/how-to-sikuli-and-robot-framework.html on a Windows XP SP3 PC and the results were good.

I had to make a change in the verifyResult function, though.
I added the following line for the case when the actual and expected results were different:
    raise AssertionError('Actual and expected results are different!')

I had Python 2.7.2 and Jython 2.5.1 installed.

I am going to try Sikuli X-1.0rc3 one more time and see if it works.

Revision history for this message
Peter Kim (pd-kim) said :
#12

So what I have found out so far:

On Windows XP SP3 PC, I can get Robot Framework work with Sikuli X-1.0rc2 but not with 1.0rc3.
I do not think I have the skill to figure out why it does not work on rc3.

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

The following setup works on my Win 7, so I guess it will work on XP too, since these are basics.

As you can see, I am using RFW 2.6.3 (but I do not think, that matters anyhow).

-------- the work folder c:\rfw contains

robotframework-2.6.3.jar
sik_module.sikuli
some-test.txt
runrfw.cmd

for this comment, it is assumed, that everything is stored here.
If you have other needs, it might be necessary, to adjust path's accordingly.

--- the basic batch file runrfw.cmd

set work=c:\rfw\
set rfwj=%work%robotframework-2.6.3.jar
set sikj=c:\Program Files\Sikuli X\sikuli-script.jar
set CLASSPATH=%rfwj%;%sikj%
set JYTHONPATH=%work%sik_module.sikuli;%rfwj%\Lib;%sikj%\Lib
java org.robotframework.RobotFramework %*

-------- rfw testing setup some-test.txt

*** Settings ***
Library OperatingSystem
Library sik_module

*** Variables ***
${MESSAGE} Hello from RobotFrameWork!

*** Test Cases ***
Sikuli Test Script [Documentation] Script test
    Log calling function from Sikuli script
    sik_popup used from script module

-------- keywords setup with Sikuli script: sik_module.sikuli (containing sik_module.py)

from sikuli import * # mandatory, since the script is imported
def sik_popup(text):
    popup(text)

You might do in Sikuli script anything, that is allowed to do with Python in the RFW environment.

To manage your images, the following might be the easiest way:

make a e.g. LoadSikuliScripts.py containing:
from sikuli import *
from script1 import *
from script2 import *
....

and add to test settings:
Library LoadSikuliScripts

this would use Sikuli to import all your scripts and populate the image path accordingly.

-------- usage

cd c:\rfw
runcfw <options> <test-definition>

where
<options> might be any RFW command line options
<test-definition> one or more RFW files containing test setups (.html, .tsv, .txt, ...)

Revision history for this message
Peter Kim (pd-kim) said :
#14

I tried it on Windows XP SP3 PC but it did not work.

I then tried it on Windows 7 and had following error messages:

C:\>cd rfw

C:\rfw>dir
 C 드라이브의 볼륨에는 이름이 없습니다.
 볼륨 일련 번호: 20C5-D5AF

 C:\rfw 디렉터리

2011-10-18 오전 08:31 <DIR> .
2011-10-18 오전 08:31 <DIR> ..
2011-10-25 오전 09:04 162,643 log.html
2011-10-25 오전 09:04 1,969 output.xml
2011-10-25 오전 09:04 183,057 report.html
2011-10-10 오후 02:32 13,816,298 robotframework-2.6.3.jar
2011-10-25 오전 08:55 234 runrfw.bat
2011-10-18 오전 08:23 <DIR> sik_module.sikuli
2011-10-18 오전 08:34 250 some-text.txt
               6개 파일 14,164,451 바이트
               3개 디렉터리 285,326,041,088 바이트 남음

C:\rfw>runrfw some-text.txt

C:\rfw>set work=c:\rfw\

C:\rfw>set rfwj=c:\rfw\robotframework-2.6.3.jar

C:\rfw>set sikj=c:\W7\Sikuli X\sikuli-script.jar

C:\rfw>set CLASSPATH=c:\rfw\robotframework-2.6.3.jar;c:\W7\Sikuli X\sikuli-scrip
t.jar

C:\rfw>set JYTHONPATH=c:\rfw\sik_module.sikuli;c:\rfw\robotframework-2.6.3.jar\L
ib;c:\W7\Sikuli X\sikuli-script.jar\Lib

C:\rfw>java org.robotframework.RobotFramework some-text.txt
[ ERROR ] Error in file 'C:\rfw\some-text.txt' in table 'Settings': Non-existing
 setting 'Library sik_module'.
[ ERROR ] Error in file 'C:\rfw\some-text.txt' in table 'Variables': Setting var
iable '${MESSAGE} Hello from RobotFrameWork!' failed: Invalid variable name '${M
ESSAGE} Hello from RobotFrameWork!'.
==============================================================================
Some-Text
==============================================================================
Sikuli Test Script [Documentation] Script test | FAIL |
No keyword with name 'Log calling function from Sikuli script' found.
------------------------------------------------------------------------------
Some-Text | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: C:\rfw\output.xml
Log: C:\rfw\log.html
Report: C:\rfw\report.html

C:\rfw>

Revision history for this message
Peter Kim (pd-kim) said :
#15

I am new to Robot Framework. It seems there was a problem with the syntax in the test data file called some-text.txt. Library and the Sikuli module needed to be separated by two or more spaces but I had it separated by one space. After fixing it, I have a different error message. I will read the Robot Framework user manual.

C:\rfw>runrfw some-text.txt

C:\rfw>set work=c:\rfw\

C:\rfw>set rfwj=c:\rfw\robotframework-2.6.3.jar

C:\rfw>set sikj=c:\W7\Sikuli X\sikuli-script.jar

C:\rfw>set CLASSPATH=c:\rfw\robotframework-2.6.3.jar;c:\W7\Sikuli X\sikuli-scrip
t.jar

C:\rfw>set JYTHONPATH=c:\rfw\sik_module.sikuli;c:\rfw\robotframework-2.6.3.jar\L
ib;c:\W7\Sikuli X\sikuli-script.jar\Lib

C:\rfw>java org.robotframework.RobotFramework some-text.txt
==============================================================================
Some-Text
==============================================================================
Sikuli Test Script [Documentation] Script test | FAIL |
No keyword with name 'Log calling function from Sikuli script' found.
------------------------------------------------------------------------------
Some-Text | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: C:\rfw\output.xml
Log: C:\rfw\log.html
Report: C:\rfw\report.html

Revision history for this message
Peter Kim (pd-kim) said :
#16

There were few more places where I had to separate fields by two or more spaces in the test data file. In Test Cases section, Log and sik_popup needed to be followed by two or more spaces.

After that, RF with RC3 worked on Windows 7.

I like Windows 7 so much better that I am not sure I want to go back to Windows XP to test if RFworks with RC3 on XP.

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

I think, it should not make a difference, wether running on WinXP or Win7.

Sorry for the troubles with the spaces, don't know, why that happened, when posting the snippets.

Revision history for this message
Ben Turner (ben-turner) said :
#18

Just spent an evening wrestling with this on Windows 7 using that latest (v2.6.3) robot framework.

In the end, I got all the errors above, and fixed them with the .cmd file supplied by RaiMan. But being stubborn, I wanted to get the batch file sorted out rather than need to send ENV variables, so I distilled the .cmd file down and got the following batch file working - it's almost the same as everything posted above, in fact I'm scared to look for differences as this now WORKS, but I think it's the python path having RobotFramework Lib in it, and a few native windows slashes too :

@echo off

set sikuli_jar=C:\Program Files\Sikuli X\sikuli-script.jar

java -cp "robotframework-2.6.3.jar;%sikuli_jar%" ^
     -Dpython.path="robotframework-2.6.3.jar\Lib;%sikuli_jar%\Lib" ^
     org.robotframework.RobotFramework ^
     --pythonpath=calc.sikuli ^
     --outputdir=results ^
     --loglevel=TRACE ^
  %*

Note that the calc.sikuli can go into the -Dpython.path too - not sure it matters which. It might do when I start on multiple sikuli files in one larger test, but we'll get to that later...

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

@ Ben -- Thanks.

stubborn is ok, but I always try to avoid repeating the same path names or other stuff in any script, so I use variables.

And the history of my post was, that I used an RFW external standalone Jython 2.5.2 installation (which was the request in the beginning).

Revision history for this message
Sergio (sergio-br) said :
#20

Hello.
I am sorry but I couldn't figure out how to solve the error on loading sikuli module (in import from sikuli *) even after reading all this thread.
I've been confused about what way (of the two described in Mike's Cognition blog) of running you are talking about: by jybot.bat or robottest.bat.
If there is any tutorial like that one in the blog, with apdated steps, could you tell me?
Or, if not, could someone gimme a little list of steps to run the calc example using Sikuli X 1.0 rc3 at Windows 7?
Thanks in advance.

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

@ sergio
To try out the calc test example on Mikes blog might be one of your second steps, after you have been successful in setting up an environment using RobotFrameWork and Sikuli together according to the above comment #13.

Clarify, if I did not get you right.

Revision history for this message
Sergio (sergio-br) said :
#22

Thank you RaiMan
Now I got calc working.
But I can't make the images to be found.

"To manage your images, the following might be the easiest way:

make a e.g. LoadSikuliScripts.py containing:
from sikuli import *
from script1 import *
from script2 import *
....

and add to test settings:
Library LoadSikuliScripts

this would use Sikuli to import all your scripts and populate the image path accordingly."

I made a LoadSikuliScripts.sikuli in the same folder of calc.sikuli.
Its content is:
from sikuli import *
from calc import *

And my Test.txt file is:
*** Settings ***
Library calc.Calculator WITH NAME Calculator
Library LoadSikuliScripts

*** Test Cases ***
v
    Start App
    Verify App
    Perform Action 2 + 2
    Verify Result 4

My runfw.bat:
set work=C:\Users\Sergio\sikuli\rfw
set rfwj=%work%\robotframework-2.7a1.jar
set sikj=%work%\sikuli-script.jar
set CLASSPATH=%rfwj%;%sikj%
set JYTHONPATH=%work%\LoadSikuliScripts.sikuli;%work%\calc.sikuli;%rfwj%\Lib;%sikj%\Lib
java org.robotframework.RobotFramework --outputdir=results %*

The log:
TEST CASE: v
Full Name: Teste.v
Start / End / Elapsed: 20120120 12:08:11.279 / 20120120 12:08:26.245 / 00:00:14.966
Status: FAIL (critical)
Message: FindFailed: can not find CalcApp.png on the screen.
+KEYWORD: Calculator.Start App
+KEYWORD: Calculator.Verify App
- KEYWORD: Calculator.Perform Action 2, +, 2
Start / End / Elapsed: 20120120 12:08:20.469 / 20120120 12:08:26.243 / 00:00:05.774
12:08:26.218 INFO [error] CalcApp.png looks like a file, but can't be found on the disk. Assume it's text.
12:08:26.242 FAIL FindFailed: can not find CalcApp.png on the screen.

My calc.sikuli:

from __future__ import with_statement
from sikuli.Sikuli import *

class Calculator(object):

 def __init__(self):
  self.appCoordinates = (0, 0, 1024, 768)

 def startApp(self):
  calcApp = App("Calculator")
  if not calcApp.window():
    App.open("calc.exe"); wait(2)
  calcApp.focus(); wait(1)

 def verifyApp(self):
  # check application
  if exists("CalcApp.png"):
   print("PASS: Calculator window appeared")
  else:
   print("FAIL: No calculator window")

 def performAction(self, *args):
  # get application region
  find("CalcApp.png")

  match = getLastMatch()
  self.appCoordinates = (match.getX(), match.getY(), match.getW(), match.getH())
  appRegion = Region(*self.appCoordinates)

  #rewrite action
  action = args[1]
  if args[1] == '+':
   action = 'Plus'
  elif args[1] == 'exp':
   action = 'Exp'

  with appRegion:
   click("btnC.png")

   click( "C:\Users\Sergio\sikuli\rfw\calc.sikuli\btn%s.png" % (args[0],) )
   click( "C:\Users\Sergio\sikuli\rfw\calc.sikuli\btn%s.png" % (action,) )
   click( "C:\Users\Sergio\sikuli\rfw\calc.sikuli\btn%s.png" % (args[2],) )

   click("btnEqual.png")

 def verifyResult(self, *args):
  expected_result = str(eval(''.join(args)))
  actual_result = self.getResultFromClipboard()

  #verification
  if actual_result == expected_result:
   print("PASS: Action performed correctly and result equals %s" % expected_result)
  else:
   print("FAIL: Actual result '%s' is not equal to expected result '%s'" % (actual_result, expected_result))

 def getResultFromClipboard(self):
  type('c', KEY_CTRL)
  return str(Env.getClipboard())

 def runTest(self):
  self.startApp()
  self.verifyApp()

  actions = '2+2'
  self.performAction(*actions)
  self.verifyResult(*actions)

if __name__ == "__main__":
 addImagePath("calc.sikuli")
 calc = Calculator()
 calc.runTest()

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

@Sergio:

On RFW Library level, you have to reference .py files not .sikuli folders ! (go back and read carefully ;-)

So just repair that and it should work.