← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #665137]: Object orientation in Python scripts

 

Question #665137 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/665137

    Status: Open => Answered

RaiMan proposed the following answer:
I am not here, to teach you whatever programming techniques, but your
approach as shown above is neither obviously needed nor is it correct or
runnable.

first at your comments
import geraCPF # just so >> if I do this, it does not work for me.

what is the problem? import only makes the contents of a Python module
available in this context, contained code at indent level 0 is executed
once at import time. nothing else happens here. In SikuliX a Python
module can be another script xxx.sikuli. The contents of a module are
named using the dotted notation of OO: moduleName.function() calls a
function() that is defined at indent level 0 in module modulename.

observe() # not sure, what this should do???
observe() without any active onXXX() defined for the respective region (SCREEN in this case) does not do anything, simply comes back instantly (read: http://sikulix-2014.readthedocs.io/en/latest/region.html#observing-visual-events-in-a-region)

#exit() # not needed >> I have to exit from the script execution and return to SikuliX.
exit() is only needed (like break or continue) if you want to terminate the scriptrun from somewhere inside the code (usually at error situations). If a script comes to the point of not having any more statements, it ends anyways.
Be aware: exit() ends the complete scriptrun, even if it is called somewhere deep in a function call chain, hence it DOES NOT return to the caller.

--- the only way to automate this test is using SikuliX
might well be, but the headline here is not SikuliX, but testing.
And every programmatical test is an automation by itself: it drives an application through some steps and checks the results against expectations (assertion). For this we have a world of testing frameworks.
If you want to stick with Python scripting, you might simply use unit test, where you define testcases, that are run one after the other, consist of a sequence setup/test(do something - assert)/teardown and report about success. This might be augmented by using the HTMLTestRunner.
Another option might be RobotFramework, which has a nice wrapper for SikuliX features (https://github.com/rainmanwy/robotframework-SikuliLibrary)

---  I need to test a complex desktop application that runs in Delphi
no need to invent the world again.

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.