where is sikuli-script.jar equivalent when integrating with Robotframework, Selenium

Asked by peter huang

i try to integrate Sikuli with Robotframework, Selenium.

I am using Sikuli 1.1.0 nightly wituild 20150610 in windows7 64 bit .

I am following some integration information as following:

http://www.8bitavenue.com/2012/04/sikuli-selenium-robot-framework-integration

Many information is written back to 2012. So they talked about sikuli-scripts.jar.

My question is what is the equivalent to sikuli-script.jar when I use Sikuli 1.1.0

i unzipped sikulix.jar and sikulixapi.jar in local folder 2 times sequentially. I tried to run
' jython.bat SikuliRemoteLibrary.py' but i get the Java.Lang.ExceptioninInitializerError just around

From org.sikuli.script import *.

I doubt the problem is version issue.
'

4.Copy C:\\Program Files\\Sikuli X\\sikuli-script.jar into C:\\robot\\libs. Note that this step is only to put things in one place but you can skip this step and only point to Sikuli jar file
5.Add C:\\robot\\libs\\sikuli-script.jar to your java class path. You need to set the CLASSPATH environment variable. Make sure there is no extra spaces otherwise problems may arise.
6.Run the remote server. Go to: C:\\robot\\libs and type: jython.bat SikuliRemoteLibrary.py
7.Launch RIDE. From the command line type: ride.py

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
peter huang
Solved:
Last query:
Last reply:
Revision history for this message
peter huang (huangsheng2) said :
#1

I am using JDK1.8 in windows7 64 bit.

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

The mentioned post is a bit out dated ;-)
... but thanks for the pointer: I already contacted the owner, to help him make an update.

In any case: setup with the latest nightly build and do that when new builds arise until final is out, since I am currently working with some usage issues and convenience functions that address integration.

1. supposing you have run a setup 1.1.0 with appropriate options, so you have a sikulix.jar and a sikulixapi.jar.
ALWAYS use the jars as jars, do not unzip - does not help anything at runtime.
If you want to know more about the internals: https://github.com/RaiMan/SikuliX-2014

2. you might either use sikulix.jar or sikulixapi.jar. In the letter case you need a separately installed Jython. For serious work, the approach as in the mentioned post is the recommended.
SikuliX 1.1.0 adds a few conveniences:
- https://github.com/RaiMan/SikuliX-2014/wiki/Usage-in-Java-programming
- http://sikulix-2014.readthedocs.org/en/latest/scenarios.html#using-python

my recommendation (like the steps in the mentioned post)
- with a valid Python 2.7 installation, get everything besides Sikuli running (RFW, Selenium, ...)
- install Jython 2.7 and ensure it works
- setup SikuliX (sikulixapi.jar)
- integrate Jython and sikulixapi,jar according 2. and do some basic tests with Jython interactive (or setup .py scripts with an editor or IDE and run them)
- then try to get RFW running

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

come back with runtime output if you get stuck.

Revision history for this message
peter huang (huangsheng2) said :
#4

Thanks, RailMan, You are always quick to respond.

But integration is a bit difficult.

I just type Jython SikuliRemoteLibrary.py.

I get the following error message:

[error] RunTimeINIT: ****terminating: no valid Java context for Sikulix available (java.security.CodeSource.getLocation() is null)

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

are you now on 1.1.0?

is sikulix.jar or sikulixapi.jar on java class path?

is your script setup according to comment #2 section 2.) ?

Revision history for this message
peter huang (huangsheng2) said :
#6

i am using 1.1.0 , sikulixapi.jar is on my java class path.

what is comment #2 section 2.)?

Revision history for this message
peter huang (huangsheng2) said :
#7

all the following are done

You might use export or any other appropriate method.

In cases you do not want to run scripts from inside the SikuliX IDE or from command line using the SikuliX command scripts or jar-files, you might setup your own Jython environment and run scripts.

Apply the following steps, to get a Jython environment, that is SikuliX aware:

download the installer package from Jython Downloads
install (usually by double-clicking the package) using the standard setup into an empty folder
test by running <jython-folder>/bin/jython from a commandline, which should open an interactive Jython session, that allows, to run Python statements line by line
make sure, that pip and easy_install are available:
<jython-folder>/bin/pip exists
<jython-folder>/bin/easy_install exists
if this is not the case run <jython-folder>/bin/jython -m ensurepip on a commandline and check again
if this is still not the case follow the steps further below Fallback without pip
run <jython-folder>/bin/pip install jip to install the package jip, which allows to add Java libraries easily to your Jython environment
add any needed Python package (must not depend on C-based stuff) using pip, easy-install or manual methods into <jython-folder>/Lib/site-packages and/or use jip for adding Java libraries preferably from Maven Central

Revision history for this message
peter huang (huangsheng2) said :
#8

my enviroment variables are as following:

ALLUSERSPROFILE=C:\ProgramData
ANDROID_HOME=C:\Users\witon\AppData\Local\Android\sdk
ANT_HOME=D:\apache-ant-1.9.4
APPDATA=C:\Users\witon\AppData\Roaming
asl.log=Destination=file
ChocolateyInstall=C:\ProgramData\chocolatey
Classpath=.;C:\Program Files\Java\jdk1.8.0_45\lib\dt.jar;C:\Program Files\Java\jdk1.8.0_45\lib\tools.jar; E:\Sikulix-2014\sikulixapi.jar;E:\jython2.7.0\jython.jar;
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=WITON-PC
ComSpec=C:\Windows\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Users\witon
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_45
JYTHONPATH=E:\Sikulix-2014\sikulixapi.jar;E:\jython2.7.0;
JYTHON_HOME=E:\jython2.7.0
LOCALAPPDATA=C:\Users\witon\AppData\Local
LOGONSERVER=\\WITON-PC
M2_HOME=D:\apache-maven-3.3.3
MAVEN_HOME=D:\Server\maven
MOZ_PLUGIN_PATH=C:\Program Files (x86)\Foxit Software\Foxit Reader\plugins\
NUMBER_OF_PROCESSORS=4
OPENSSL_CONF=C:\Program Files\PostgreSQL\psqlODBC\0903\etc\openssl.cnf
OS=Windows_NT
Path=C:\Python27\;C:\Python27\Scripts;C:\ActivePython\;C:\ActivePython\Scripts;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\ThinkPad\Bluetooth Software\;C:\Program Files\ThinkPad\Bluetooth Software\syswow64;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\GitExtensions\;C:\Program Files (x86)\AMD\ATI.ACE\Core-Static;C:\Program Files\Java\jdk1.8.0_45\bin;C:\Program Files\Java\jdk1.8.0_45\jre\bin;D:\apache-ant-1.9.4\bin;D:\apache-maven-3.3.3\bin;C:\Users\witon\AppData\Local\Android\sdk\platform-tools;C:\Users\witon\AppData\Local\Android\sdk\tools;C:\Python27;C:\Program Files\Microsoft Windows Performance Toolkit\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\nodejs\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Users\witon\AppData\Roaming\Python\Scripts;E:\Sikuli\libs;;C:\Program Files\Java\jdk1.8.0_45\bin;C:\Program Files\Java\jdk1.8.0_45\jre\bin;D:\apache-ant-1.9.4\bin;D:\Server\maven\bin;C:\Users\witon\AppData\Local\Android\sdk\platform-tools;C:\Users\witon\AppData\Local\Android\sdk\tool;C:\Python27;C:\Python27\Scripts;C:\Program Files\PostgreSQL\9.4\bin;C:\Program Files\PostgreSQL\9.4\lib;C:\Program Files\nodejs;C:\Users\witon\AppData\Roaming\npm;C:\Users\witon\AppData\Roaming\npm\node_modules\grunt-cli\bin;D:\Server\maven\bin;C:\Program Files (x86)\Sikuli X\libs;D:\apache-maven-3.3.3;E:\jython2.7.0\bin;C:\Users\witon\Desktop\opencv\build\x64\vc11\bin;C:\Users\witon\Desktop\opencv\build\x64\vc11;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYM;.pyw
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 69 Stepping 1, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=4501
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SIKULI_HOME=E:\Sikulix-2014
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Users\witon\AppData\Local\Temp
TMP=C:\Users\witon\AppData\Local\Temp
USERDOMAIN=witon-PC
USERNAME=witon
USERPROFILE=C:\Users\witon
VS100COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\
VS110COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools\
VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\
windir=C:\Windows
windows_tracing_flags=3
windows_tracing_logfile=C:\BVTBin\Tests\installpackage\csilogfile.log

Revision history for this message
peter huang (huangsheng2) said :
#9

in E:\ on my disk, i have installed 4 sikuli all 1.1.0

 E:\ 的目录

2015/06/12 17:23 <DIR> Sikuli
2015/06/25 18:16 <DIR> Sikulix
2015/06/25 17:23 <DIR> Sikulix-2014
2015/06/08 03:55 <DIR> SikuliX2014
2015/06/11 21:26 2,984,506 sikulixsetup-1.1.0-20150610.230943-100-forsetup.jar
2015/06/10 14:46 <DIR> Sikuli_new
               1 个文件 2,984,506 字节
               5 个目录 142,807,056,384 可用字节

in Sikuli_Home, i am poitin

Revision history for this message
peter huang (huangsheng2) said :
#10

in Sikuli_Home, i am pointing to Sikutlix-2014. does it matter to have mutiple Sikuli folders?

Revision history for this message
peter huang (huangsheng2) said :
#11

I have deleted mutiple Sikuli folders but the same errors. No valid Java context for Sikuli availble Java.Security.Codesource.Getlocation() is null

Revision history for this message
peter huang (huangsheng2) said :
#13

what is the getlocation() here? is anything wrong?

the programme i want to run with Jython is as following:

import sys
import org.sikuli.basics.SikulixForJython
# from sikuli.Sikuli import *
from robotremoteserver import RobotRemoteServer
from org.sikuli.script import *

class SikuliRemoteLibrary:

 def __init__(self):
  self.SS = Screen()
  self.PT = Pattern()

 def _wait(self, imgFile, timeOut, similarity):
  try:
   self.PT = Pattern(imgFile)
   self.PT = self.PT.similar(float(similarity))
   self.SS.wait(self.PT, float(timeOut))
  except FindFailed, err:
   print "ERR: _wait"
   raise AssertionError(err)

 def click_object(self, imgFile, timeOut, similarity):
  try:
   self._wait(imgFile, timeOut, similarity)
   self.SS.click(imgFile)
  except FindFailed, err:
   raise AssertionError("Cannot click [" + imgFile + "]")

 def object_exists(self, imgFile, similarity, timeOut):
  try:
   self._wait(imgFile, timeOut, similarity)
  except FindFailed, err:
   raise AssertionError("Could not find [" + imgFile + "]")

 def type_at_object(self, imgFile, txt, timeOut, similarity):
  try:
   self._wait(imgFile, timeOut, similarity)
   self.SS.type(imgFile, txt)
  except FindFailed, err:
   raise AssertionError("Cannot type at [" + imgFile + "]")

 def paste_at_object(self, imgFile, txt, timeOut, similarity):
  try:
   self._wait(imgFile, timeOut, similarity)
   self.SS.paste(imgFile, txt)
  except FindFailed, err:
   raise AssertionError("Cannot paste at [" + imgFile + "]")

if __name__ == '__main__':
 SRL = SikuliRemoteLibrary()
 RobotRemoteServer(SRL, *sys.argv[1:])

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

starting to comment your stuff

***** the start of your program is not correct:

--- you have:
import org.sikuli.basics.SikulixForJython
# from sikuli.Sikuli import *
from robotremoteserver import RobotRemoteServer
from org.sikuli.script import *

--- but MUST be
import org.sikuli.basics.SikulixForJython
from sikuli import *
from robotremoteserver import RobotRemoteServer
# from org.sikuli.script import * # THIS IS SIMPLY forbidden!!!
# the API needed for Jython scripting is made available by
# from sikuli import *

**** use exists() instead of wait to avoid exception handling:

instead of
try:
  self.SS.wait(self.PT, float(timeOut))
except:
  ...

use
if not self.SS.exists(self.PT, float(timeOut)):
    # handle the failed situation
# continue with the normal workflow

use

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

@ comment #8:

you have C:\Program Files (x86)\Sikuli X\libs in your system path.
When working with 1.1.0 you should purge or hide everything, that has to do with any prior Sikuli version.

SIKULI_HOME is no longer needed and not recognised.
A correctly setup sikulix.jar/sikulixapi.jar knows, where it is.

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

the mentioned error
[error] RunTimeINIT: ****terminating: no valid Java context for Sikulix available (java.security.CodeSource.getLocation() is null)

simply means, that the class org.sikuli.script.RunTime.class (contained in sikulixapi.jar) cannot be located on the class path, which in turn is odd, since the message is produced from inside the class RunTime.

Conclusion: you have some terrible mix in your setup.

So before doing any more complex things, you should start again from beginning and verify each step.

You should not do anything in your environment, but setup a command file, that at runtime sets up the correct environment.
So you have more control.

Revision history for this message
peter huang (huangsheng2) said :
#17

thanks Railman, one more question for Sikuli setup. When Sikuli Setup, users are asked to choose options, can i choose options 1, 2 at the same time?
Thanks.

Revision history for this message
Clark Burbidge (clarkburbidge) said :
#18
Revision history for this message
Zeks (enmarantispam) said :
#19

Correct usage of jython requires jython -cp YOUR-CLASSPATH script.py

Revision history for this message
peter huang (huangsheng2) said :
#20

i have got the key points. It is related to Jython classpath.
I use following Jythonpath, it works.
If Sikulixapi.jar is one Jar, why JYTHONPATH should be like following?
%sikulix_jar%/Lib??? Sounds a little strange to me.

set sikulix_jar=E:\Sikulix-2014\sikulixapi.jar

set CLASSPATH=%sikulix_jar%
set JYTHONPATH=%sikulix_jar%/Lib;E:\JYTHON2.7.0

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

in comment #14 I told you:

MUST BE:
import org.sikuli.basics.SikulixForJython
from sikuli import *

SikulixForJython is the helper, to put the sikulixapi.jar/Lib on sys.path, if sikulixapi.jar is on the CLASSPATH.

sikulixapi.jar/Lib
MUST be on sys.path/JYTHONPATH, because here the Python API is located and especially the folder sikuli to make the
from sikuli import *
working.

so you either use JYTHONPATH (as you did now) or class path only, but then <import org.sikuli.basics.SikulixForJython> as first statement in the main python script (or at least before you touch any SikuliX feature or issue the <from sikuli import *>

These are the current documented usage rules ;-)

I am working on a more automatic solution for all that especially with respect to the integration of Selenium and RobotFramework.