Skip to content

Commit

Permalink
Small fix and documentation improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian V committed Oct 15, 2021
1 parent ccf1366 commit ad68c5e
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*.pyc
results/
build/
robotframework_sikulixlibrary.egg-info/
dist/
.vscode/
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ See [keyword documentation](https://adrian-evo.github.io/SikuliXLibrary.html).
- Py4J server is enabled from SikuliX 2.0.5 onward and currently advertised as experimental. However, this library is working as expected with Py4J.
- Recommended to use environment variable SIKULI_HOME that point to sikulix local directory
5. `pip install robotframework-sikulixlibrary`
6. Check Known issues section below if libspec is not generated within your environment (RF IDE tool) and thus library keywords are not recognised

While JPype JVM is always started automatically, Py4J JVM can be started manually or automatically. To start manually, use the command:

Expand Down Expand Up @@ -75,9 +76,7 @@ Git clone, and if not using pip install for this library, then just point PYTHON

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 Robot Editor - RED (https://github.com/nokia/RED) or Eclipse with RED plugin is also possible with this library, for both Robot Framework and Pyton code.

Note: Since Robot Framework 4.x is no longer supported by RED and Eclipse, the recommended new tool is Visual Studio Code with Robot Framework Language Server by Robocorp.
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).

# Supported Operating Systems

Expand Down
5 changes: 4 additions & 1 deletion SikuliXLibrary/sikulixlibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SikuliXLibrary(SikuliXRegion,
With the help of this new library, SikuliX implementation can be used now natively with Robot Framework and Python 3.x:
- robotremoteserver and Remote library are not needed anymore
- debugging with Robot Editor - RED or Eclipse is finally possible for both Robot Framework and Python code
- debugging with some RF supporting tools
- very easy to extend the library with new keywords, or overwrite existing keywords and methods by extending the main class, e.g.
| class ImageHorizonLibraryMigration(SikuliXLibrary):
Expand Down Expand Up @@ -75,6 +75,9 @@ class SikuliXLibrary(SikuliXRegion,
- similar - minimum similarity. If not given, the default is used. Can be set as img=similarity
- mask - an image with transparent or black parts or 0 for default masked black parts. Should be set as img:mask, img:0, img:mask=similarity or img:0=similarity
- dx, dy - define click point, either relative to center or relative to upper left corner (default with set_offsetCenterMode)
Note: within RF, coordinates can be given both as string or numbers, for any keyword that needs coordinates, e.g.:
'Region Click 10 10'
'Region Click ${10} ${10}
- useLastMatch - if True, will assume the LastMatch can be used otherwise SikuliX will do a find on the target image and click in the center of it.
if implicit find operation is needed, assume the region is the whole screen.
Expand Down
10 changes: 10 additions & 0 deletions SikuliXLibrary/sikulixlogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ def __init__(self, logImages=True):
def set_sikuli_resultDir(self, path):
'''
Used to set the directory where to save the screenshots for the log file
| Set Sikuli resultDir | path |
'''
SikuliXLogger.resultDir = path

@keyword
def set_passedLogImages(self, mode):
'''
Enable or disable logging of the images when keyword passes
| Set passedLogImages | ${True} |
'''
scr = self.passedLogImages
self.passedLogImages = mode
Expand All @@ -43,6 +47,8 @@ def set_passedLogImages(self, mode):
def set_failedLogImages(self, mode):
'''
Enable or disable logging of the images when keyword fails
| Set failedLogImages | ${True} |
'''
scr = self.failedLogImages
self.failedLogImages = mode
Expand All @@ -52,6 +58,8 @@ def set_failedLogImages(self, mode):
def set_notFoundLogImages(self, mode):
'''
Enable or disable logging of the images when the image is not found (for keywords that does not throw exception)
| Set notFoundLogImages | ${True} |
'''
scr = self.notFoundLogImages
self.notFoundLogImages = mode
Expand All @@ -61,6 +69,8 @@ def set_notFoundLogImages(self, mode):
def log_warning(self, msg):
'''
Print text in the log with the label WARNING:
| Log Warning | msg |
'''
logger.warn("WARNING: %s" % msg)

Expand Down
9 changes: 6 additions & 3 deletions SikuliXLibrary/sikulixregion.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ def region_getFindFailedResponse(self):
def region_setRect(self, x, y, w, h):
'''
Set position and dimension of the current region to new values. Upper left corner, width and height.
Can be given as strings or numbers with ${}
Current region as full screen:
| Region | SetRect | 0 | 0 | 1920 | 1080 |
| Region | SetRect | 0 | 0 | 1920 | 1080 |
| Region | SetRect | ${0} | ${0} | ${1920} | ${1080} |
'''
self.appRegion.setRect(x, y, w, h)
self.appRegion.setRect(int(x), int(y), int(w), int(h))

# Region - find operations
@not_keyword
Expand Down Expand Up @@ -318,6 +320,7 @@ def region_click(self, target=None, dx=0, dy=0, useLastMatch=False):
Region Click with no arguments will either click the center of the last used Region or the lastMatch, if any is available.
| Region Click | image.png=0.7 | dx | dy |
| Region Click | image.png=0.7 | ${dx} | ${dy} |
| Region Click | image | dx | dy | useLastMatch=${True} |
'''
return self._region_mouseAction('click', target, dx, dy, useLastMatch)
Expand Down Expand Up @@ -356,7 +359,7 @@ def region_mouseMove(self, xoff, yoff):
| Region MouseMove | x | y |
'''
return self.appScreen.mouseMove(xoff, yoff)
return self.appScreen.mouseMove(int(xoff), int(yoff))

# Region - highlights operations
@keyword
Expand Down
2 changes: 1 addition & 1 deletion SikuliXLibrary/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.1"
__version__ = "1.2.2"
13 changes: 13 additions & 0 deletions test/debug test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!python

"""
Description: Utility that will allow to debug and break into e.g. custom python libraries. Add a configuration within Visual Studio Code
to run Python file and then execute this file. Set a breakpoint in the Python library as needed.
"""

from pathlib import Path

import robot

if __name__ == "__main__":
robot.run('test/test_defaultlibrary_win.robot', outputdir='test/results/default')
21 changes: 14 additions & 7 deletions test/test_defaultlibrary_win.robot
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,27 @@ Test Notepad With SikuliX
# default min similarity
${prev} settings set MinSimilarity ${0.9}

region setRect 0 0 1920 1080
region setRect ${0} ${0} ${1920} ${1080}

# step 1
log Step1: open Notepad
app open C:/Windows/System32/notepad.exe
#region wait iNotepad mod.PNG

# different mask and similarity options given
region wait iNotepad.PNG
region wait iNotepad.PNG:0
region wait iNotepad.PNG:iNotepad2
region wait iNotepad.PNG:0=0.69
region wait iNotepad.PNG:iNotepad2=0.71
region wait iNotepad:iNotepad2=0.71
region wait iNotepad.PNG:iNotepad2.PNG=0.71

#region wait iNotepad.PNG:0
#region wait iNotepad.PNG:iNotepad2
#region wait iNotepad.PNG:0=0.69
#region wait iNotepad.PNG:iNotepad2=0.71
#region wait iNotepad:iNotepad2=0.71
#region wait iNotepad.PNG:iNotepad2.PNG=0.71

region click iNotepad ${50} ${50}
region mouseMove 100 100
region click iNotepad 50 50

#pass execution .

# step 2
Expand Down

0 comments on commit ad68c5e

Please sign in to comment.