Continue script execution despite error

Asked by Samuel Schlegel

Hi,

I´m using Sikuli for GUI-Testing.
It would be nice, if there were a possibility, that would allow me to continue test-execution even if a error occures (e.g. if a UI-control can´t be found, or if a result is incorrect, the script should just continue executing so the next control can be tested).

At the moment when the first error occurs, the script stops executing, the line inside the script where the error occured is getting marked and the error(s) are shown inside the Message dialog.
This would be appropriate to find the errors once the test finished, but I need the script to continue executing after such a error has been logged.

Regards
Sam

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1
Revision history for this message
Eugene S (shragovich) said :
#2

You could just create a custom finder function. For example something like that:

def tryDetect(object,retries,highLight=1):
 """Attempts to detect the "object" for "retries" times.
 """
 localLog.info("Trying to detect %s image... %d attempts will be made", object, retries)
 for n in range(retries):
  if exists(object):
   localLog.info("%s image detected!", object)
   detectedObj = find(object)
   if (highLight == 1):
    localLog.debug("highLight argument is set to %d",highLight)
    detectedObj.highlight(1)
   else:
    localLog.debug("highLight argument is set to %d",highLight)
   failStatus = 0 # PASS => failStatus = 0
   return detectedObj
  else:
   localLog.info("%s image was not detected in iteration %d", object, n+1)
   waitFor(1)
   if n == retries - 1: #If the number of iterations exhausted and the desired object was not yet detected
    localLog.debug("Number of retries exceeded...")
    failStatus = 1 # FAIL => failStatus = 1
    takeScreenShot(testName)
    localLog.error("%s test step FAILED!", testName)
    exit(1)

Revision history for this message
Samuel Schlegel (samuel-schlegel) said :
#3

Thank you for replying so rapidly : )

On a first glance it seems to me like defining a "skip" behaviour for certain events like getFindFailedResponse might be useful if the logs are giving enough info to determine where and why a skip occured.
Defining log-texts manually inside the script might be too much effort since the huge number of controls is the reason why I want to automate them.
Anyways I´ll try your mentioned solutions and ask again if I encounter any more problems.

Thanks again!

Revision history for this message
Jason (jasonnaviello) said :
#4

I am having the same problem as the OP. I am testing a GUI and I do not want the script to stop running after it reaches a failure (or a missing object).

I am using the> assert exists(#link_to_image#), 5) When the script detects a missing image it will stop in the middle and log the error in the message field. I do not want to "SKIP" , the missing image in a "Not Found" situation and I do not want to "ABORT" or "RETRY" either. The purpose of my testing is to detect issues with the GUI not skip over them.

Is there another way to report the error at the end once the script is finished without stopping in the middle?

Revision history for this message
Eugene S (shragovich) said :
#5

please start a new question

Can you help with this problem?

Provide an answer of your own, or ask Samuel Schlegel for more information if necessary.

To post a message you must log in.