Go to the next script

Asked by Raphael Silva

I am using the following script:

import os
dir = os.path.dirname(getBundlePath()) # our working dir with the scripts

# run some scripts in sequence
for script in ("LoginSoul", "Lancaritem"):
    scriptsik = script + ".sikuli"
    scriptpy = os.path.join(scriptsik, script + ".py")
    setBundlePath(os.path.join(dir, scriptsik)) # folder for images
    execfile(os.path.join(dir, scriptpy)) # runs the code

but when an error happens in the first script(LoginSoul), it did not run the second script. How do I not to run when there is an error in one of the scripts?

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Raphael Silva
Solved:
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

Since execfile(sub) simply runs the lines of code in sub as if they were physically (something like include in other languages), the main scrip stops with the given error, if sub crashes.

So if you want to have the main script stopped if an error occurs in the subs, you have what you want.

If I understood wrong: try to explain again, what you want to achieve.

Revision history for this message
Raphael Silva (raphaelcoel) said :
#2

I want it to continue running other test case even if the first fails.

example

LoginSoul.sikuli (error)

passes to the next test case in my case Lancaritem.sikuli.

at the end looks like this:

LoginSoul.sikuli (error)
Lancaritem.sikuli (ok)

Today happens like this:
LoginSoul.sikuli (error)
Lancaritem.sikuli (not running)

Revision history for this message
RaiMan (raimund-hocke) said :
#3

# run some scripts in sequence
for script in ("LoginSoul", "Lancaritem"):
    scriptsik = script + ".sikuli"
    scriptpy = os.path.join(scriptsik, script + ".py")
    setBundlePath(os.path.join(dir, scriptsik)) # folder for images
    try:
        execfile(os.path.join(dir, scriptpy)) # runs the code
        print script, "ran with success"
    catch Exception, e:
        print script, "ran with some error:", e.message

Revision history for this message
Raphael Silva (raphaelcoel) said :
#4

thank you

but is displaying the error:

[error] Mensagem de erro: SyntaxError: ("no viable alternative at input 'catch'", ('C:\\DOCUME~1\\RAPHAE~1.SIL\\CONFIG~1\\Temp\\sikuli-tmp58748340155989666.py', 11, 4, ' catch Exception, e:\n'))

Revision history for this message
RaiMan (raimund-hocke) said :
#5

uups, some Babylon syndrome ;-)

in Python it is except instead of catch.

Revision history for this message
Raphael Silva (raphaelcoel) said :
#6

Thank you ! My problem was solved.