← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #156247]: How are exception handled when using imported scripts?

 

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

    Status: Open => Answered

RaiMan proposed the following answer:
Ok, but exactly this should work with your solution, since image not
found situations (except with exists() and waitVanish()) produce
FindFailed exceptions (if you have not switched it off), that are
catchable with try/except.

taking the above example (mind the "naked" except: to catch ALL
exceptions)

Script:
---------
def test1():
 openApp ("Notepad.exe")
def test2():
 click("some-image.png")
def test3():
 assert(False)

theTests = (test1, test2, test3)
theResults = []

for test in theTests:
 try:
  test()
  print test.__name__, "ok"
 except:
  theResults.append(test.__name__)
  print test.__name__, "Failed"

print theResults

should print, if "some-image.png" cannot be found when click() is
processed:

Result:
---------
[log] App.open Notepad.exe(348)
test1 ok
test2 Failed
test3 Failed
['test2', 'test3']

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.