diff --git a/.gitignore b/.gitignore index 0dde16b..8f88f1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ *.pyc results/ +build/ +robotframework_sikulixlibrary.egg-info/ +dist/ +.vscode/ \ No newline at end of file diff --git a/README.md b/README.md index 3469eee..779f684 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 diff --git a/SikuliXLibrary/sikulixlibrary.py b/SikuliXLibrary/sikulixlibrary.py index 8858406..b4e6daa 100644 --- a/SikuliXLibrary/sikulixlibrary.py +++ b/SikuliXLibrary/sikulixlibrary.py @@ -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): @@ -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. diff --git a/SikuliXLibrary/sikulixlogger.py b/SikuliXLibrary/sikulixlogger.py index 02fbff8..ce66f68 100644 --- a/SikuliXLibrary/sikulixlogger.py +++ b/SikuliXLibrary/sikulixlogger.py @@ -27,6 +27,8 @@ 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 @@ -34,6 +36,8 @@ def set_sikuli_resultDir(self, path): def set_passedLogImages(self, mode): ''' Enable or disable logging of the images when keyword passes + + | Set passedLogImages | ${True} | ''' scr = self.passedLogImages self.passedLogImages = mode @@ -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 @@ -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 @@ -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) diff --git a/SikuliXLibrary/sikulixregion.py b/SikuliXLibrary/sikulixregion.py index 3abd72b..a96ad07 100644 --- a/SikuliXLibrary/sikulixregion.py +++ b/SikuliXLibrary/sikulixregion.py @@ -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 @@ -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) @@ -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 diff --git a/SikuliXLibrary/version.py b/SikuliXLibrary/version.py index a955fda..bc86c94 100644 --- a/SikuliXLibrary/version.py +++ b/SikuliXLibrary/version.py @@ -1 +1 @@ -__version__ = "1.2.1" +__version__ = "1.2.2" diff --git a/test/debug test.py b/test/debug test.py new file mode 100644 index 0000000..62399cc --- /dev/null +++ b/test/debug test.py @@ -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') diff --git a/test/test_defaultlibrary_win.robot b/test/test_defaultlibrary_win.robot index a086a6a..0d0065d 100644 --- a/test/test_defaultlibrary_win.robot +++ b/test/test_defaultlibrary_win.robot @@ -40,6 +40,9 @@ 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 @@ -47,13 +50,17 @@ Test Notepad With SikuliX # 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