use of wait() is ambiguous concerning exception FindFailed
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SikuliX |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
Not really a bug --- to evaluate together with renewal of api
We need a companion for wait(), that internally does not throw FindFailed and returns None independent of setThrowExeception if not found.
Additionallly it would be very convenient to have a getThrowException() to get the current status. Same goes for getAutoWaitTime
Why?
looking along a workflow, getting a FindFailed normally means, that something on the screen is not as it should be. Therefor the standard, that find() and all the companions throw exception FindFailed if not found is a good support, to get a workflow running in a short time, with a minimum of needed statements.
If you want some special handling, you have setThrowException() and <try: except:> to do so.
But there is a "convenience gap":
if you want a wait(), to be intentionally used, to check, wether something is there within a specific time, to decide, how to go on with the workflow, its rather inconvenient to get it go.
example: the script does something on a web page. if its not already there, you have to bring it up first.
to be consistent I always use wait() for theses checks.
switchApp(browser)
if not wait(pic, timeout=0): # something to check, wether web page already there, short timeout
myGetNew(url) # privat def: to get a new window with the url opened
wait(pic) # normal or extended timeout
for the first wait(), we need a None returned, but if not there we get FindFailed and the script stops.
second try:
setThrowExcepti
if not wait(pic, timeout=0): # something to check, wether web page already there, short timeout
myGetNew(url) # privat def: to get a new window with the url opened
setThrowExcepti
wait(pic) # normal or extended timeout
This works, but may impact whats happening inside myGetNew(). Since in the moment there is no getThrowException, you have to define a global yourself, to keep track.
another user made up his own _wait() to get around this:
def _wait(img, timeout=3000):
try:
s = wait(img, timeout)
except:
s = []
return s
for me this is not a solution, since its too much depending on the current api.
my current solution is:
global mySetExc # set accordingly by the excO..()
excOn() # throw
excOff() # don't throw
myGetExc() # gets current from mySetExc
with this in every def(): I always know, whats the current situation about FindFailed
check() # private that does a wait without throwing and resets to mySetExc
so my solution for the example:
switchApp(browser)
if not check(pic, timeout=0):
myGetNew(url)
wait(pic)
tags: | added: 10.0 api wait |
tags: |
added: 0.10 removed: 10.0 |
Changed in sikuli: | |
milestone: | none → 0.10.0 |
Version 0.10: new method exits() returns False instead of raising exception FindFailed