Forum Discussion

David_Shapiro's avatar
David_Shapiro
Occasional Contributor
15 years ago

How to Capture errors?

I have a fairly simply script, but I want to improve it so that it shows the error seen in its testStep.  I am not sure how to do this.  I tried (see code below) to put result.error, but that does not work.  Is there something like result.error or result.stderr or something?

/ Set the testcase name
def testcase = "order";
def request = testRunner.testCase.getTestStepByName(testcase);
def results = testRunner.results;

//assert results.size() != 0, sendAlert('Results are missing from request for ' + testcase);

def sendAlert(msg)
{
// codes sends an alert here
}

for (result in results)
{
  if (result.testStep == request)
{
log.info("request status: " + result.status);
// Set status that you want alert to go out on here
if (!(result.status ==~ /OK/))
{
    [color=green]// Instead of putting result.status, I would like to put the error message[/color]
sendAlert("Alert for " + testcase + ": " + [color=green]result.status[/color]);
    }
}
}

1 Reply

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    result.messages is an array of Strings containing error messages for the request (failed assertions). There is also result.error which returns a throwable (if an exception was thrown during the TestStep) which you can use. Good luck!

    Regards,
    Dain
    eviware.com