Command to Stop EggPlant script running on Failure

Hi,

I have a list of scripts running consecutively. However, when one script fails, the rest of the scripts are still running to the end. I am looking for a way to stop EggPlant from running on the failure of the script so that the rest of the scripts can be skipped

Any suggestions?

thanks,
Dennis

Comments

  • Hi Dennis--

    For this, you will want to use a try/catch block, and the command exit all:
    try
      script1
      script2
      script3
    catch exception
      exit all
    end try
    
    This should get you what you want. Feel free to let me know if this isn't what you're after.
  • Hi Allen,
    I have a block of codes below. The result of that is I will get 4 emails separately. I was hoping to get one email when the script failed on "Test 1". With your suggestion, shall I just use the try and catch instead of the If statement in this case.
    thanks,

    Set TestAll to {
    "Test 1",
    "Test 2",
    "Test 3",
    "Test 4"
    }


    RunWithNewResults "Initial Test"
    put the result into TestResult
    if the status of TestResult is "SUCCESS" then
    Repeat with each TestScript of TestAll
    If the status of TestResult is "Failure" then
    sendMail(to:"[email protected]", from: "[email protected]", subject: "Test Failed", Body: "Script" && Testscripts && "run at" && rundate of TestResult && "had" && errors of Testesult && "errors", attachment: logfile.txt)
    Else
    RunWithNewResults TestScript
    Put the result into TestResult
    Put TestScript & ":" && status of TestResult && Return after currentReport
    End If
    End Repeat
    Log "Final Results"
    Repeat with each line of currentReport
    log it
    End repeat
    Else
    sendMail(to:"[email protected]", from: "Test Team", subject: "Test Failed", Body: "Test run at" && rundate of TestResult && "had errors")

    end If
  • That would be my suggestion, so it would look something like this:
    Set TestAll to {"Test 1","Test 2","Test 3","Test 4"} 
    
    RunWithNewResults "Initial Test" 
    put the result into TestResult 
    
    if the status of TestResult is "SUCCESSS"
      repeat with each TestScript of TestAll
        try 
          RunWithNewResults TestScript 
          Put the result into TestResult 
          Put TestScript & ":" && status of TestResult && Return after currentReport 
        catch exception
          Mail(to:"[email protected]", from: "Test Team", subject: "Test Failed", Body: "Test run at" && rundate of TestResult && "had errors")
          exit all --this will stop execution
        end try
      end repeat
    end if
    
    //do your reporting
    Repeat with each line of currentReport 
      log it 
    End repeat
    
    I hope this helps. I think in most situations this should work, unless your failure doesn't throw an exception for some reason. If you need to keep the if/else then just throw the keyphrase exit all after your sendTo command. Exit All will halt everything.
Sign In or Register to comment.