The all new, modern, SikuliX Robot Framework library for Python 3.x, based on JPype or Py4J Python modules.
It can be used with e.g. Robot Framework projects (https://robotframework.org), Robocorp projects (https://robocorp.com) - the easiest approach for beginners or with pure Python projects. Either for Test Automation type of projects, or for open source RPA (Robot Process Automation) projects.
JPype is a Python module to provide full access to Java from within Python.
Py4J enables Python programs running in a Python interpreter to dynamically access Java objects in a JVM.
This library is a wrapper to SikuliX that is exposing Java functions as Robot Framework keywords, and it can be enabled to use by choice any of the JPype or Py4J modules. This is done by creating SIKULI_PY4J environment variable and setting to 1. When not defined or set to 0, JPype is used instead. Please note that on MacOS, only Py4J can be used, while on Windows or Ubuntu, any of them is working.
While in the past the only approach to use Sikuli functionality within Robot Framework was through Remote Server with XML RPC interface (SikuliLibrary), the aim of this library is to replace that approach and make it a lot easier to use SikuliX within Robot Framework projects with a simple Library statement (i.e. no need to start remote server and so on).
Also with this implementation is very easy to extend the library with new custom keywords, for example with the purpose to create migration classes to help migrate from current Sikuli libraries or other image recognition alternatives. For practical examples check migrate folder.
pip install robotframework-sikulixlibrary
While JPype JVM is always started automatically, Py4J JVM can be started manually or automatically. To start manually, use the command:
java -jar sikulix.jar -p
(to start Py4J server) or
java -jar -DsikuliDebug=3 sikulixide.jar -p
(useful e.g. for checking sikulix debug info)
Mainly the same steps as for Windows above. However, installing Tesseract 4 seems to be challenging since e.g. brew install tesseract
will install Tesseract 5. But at least the following method from stackoverflow for installing Tesseract 4.1.3 is working.
*** Settings ***
Library SikuliXLibrary sikuli_path=sikulixide-2.0.5.jar
*** Test Cases ***
Example Test
imagePath add ${my_path}
settings set MinSimilarity ${0.9}
app open C:/Windows/System32/notepad.exe
region wait iNotepad.PNG
region paste Welcome!
from SikuliXLibrary import SikuliXLibrary
sikuli_path = 'sikulixide-2.0.5.jar'
lib = SikuliXLibrary(sikuli_path)
lib.imagePath_add('my_path')
lib.settings_set('MinSimilarity', float(0.9))
lib.app_open("C:\\Windows\\System32\\notepad.exe")
lib.region_wait('iNotepad')
lib.region_paste('Welcome!)
Git clone, and if not using pip install for this library, then just point PYTHONPATH to local robotframework-sikulixlibrary folder and execute:
python testlibrary_win.py
(or any .py file from under test directory and for OS of choice
robot --outputdir results/default test_defaultlibrary_win.robot
(or any .robot file from under test directory and for OS of choice)
or maybe on MacOS
python3 -m robot --outputdir results/default test_defaultlibrary_osx.robot
Obviously, image files from test/img/MacOS, Ubuntu or Windows might not work on specific environment and would need to be regenerated. Also for these tests SIKULI_PATH is defined and the name of SikuliX is sikulixide-2.0.5.jar
Additionally, debugging with some RF supported tools is also possible with this library, for both Robot Framework and Pyton code. Python library debugging was tested with Visual Studio Code with Robot Framework Language Server by Robocorp, by using debug test.py
file. Also Robot Framework test code from within test directory was tested with debugging, with the same tool, by creating a specific configuration within launch.json file (VSCode specific file).
Windows 10
OSX
Linux
pip install robotframework-sikulixlibrary
python -m robot --outputdir results/ubuntu test_defaultlibrary_ubuntu.robot
or python testlibrary_ubuntu.py
When using Py4J, libdoc will not generate library documentation within IDE, e.g. Visual Studio Code with Robocorp extension (Robot Framework Language Server). The workaround is to start manually SikuliX Py4J server (see above or run java -jar sikulix.jar -p
), then reload the library to generate the keyword documentation. If not using pip install for this library, then the extension settings.json need to have pythonpath set to local robotframework-sikulixlibrary folder.
When generating library documentation within IDE, the library is instantiated with no arguments and it will look for sikulix.jar file within SIKULI_HOME environment variable defined directory, so make sure this file is there even if it is a duplicate of e.g. sikulixide-2.0.5.jar. Otherwise, it is also possible to manually generate the libspec with the following command, and copy it under project folder or PYTHONPATH:
python -m robot.libdoc SikuliXLibrary::sikuli_path=path\to\sikulixide-2.0.5.jar SikuliXLibrary.libspec
See this documentation for reference: https://github.com/robocorp/robotframework-lsp/blob/master/robotframework-ls/docs/faq.md