Forum Discussion

skelkar's avatar
skelkar
Contributor
11 years ago

Error handling in Tear down script

Hi,

I am capturing rest response header "RequestId" using below script in each test suite tear down script.
It is working good but if there is no requestId header value (which is the case for 503 errors some times) then it gives nullpointerexpecton.
**************************************
for ( testCaseResult in runner.results)
{
log.info testCaseResult
testCaseName = testCaseResult.getTestCase().name
log.info "test case name: " + testCaseName
if ( testCaseResult.getStatus().toString() == com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus.FAILED.toString() )
{
log.info "Test case " + testCaseName + " failed"
for (testStepResult in testCaseResult.getResults() )
{
if(testStepResult.getStatus().toString() == com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus.FAILED.toString())
{
def testStep = testStepResult.getTestStep()
log.info testStep.name
//do what needs to be done here to get the response content for the testStep

def ReqId = testStep.testRequest.response.responseHeaders["RequestId"].get(0)
//log.info "failed test step: "+ testStep+" RequestId is :"+ ReqId
log.info "RequestId Of Failed Step: "+testStep.name+ " = "+ReqId

}
}
}//end if
}//end for
***********************
I want script to continue and tried try catch block as below but did not work.

import java.io.*;
for ( testCaseResult in runner.results)
{
log.info testCaseResult
testCaseName = testCaseResult.getTestCase().name
log.info "test case name: " + testCaseName
if ( testCaseResult.getStatus().toString() == com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus.FAILED.toString() )
{
log.info "Test case " + testCaseName + " failed"
for (testStepResult in testCaseResult.getResults() )
{
if(testStepResult.getStatus().toString() == com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus.FAILED.toString())
{
def testStep = testStepResult.getTestStep()
log.info testStep.name


// try catch block for exception handling //

try{
def ReqId = testStep.testRequest.response.responseHeaders["RequestId"].get(0)
}
catch(NullPointerException e){log.info e}
log.info "RequestId Of Failed Step: "+testStep.name+ " = "+ReqId

}
}
}//end if
}//end for

Here control does not go insite try block please advise if i missed something.

3 Replies

  • nmrao's avatar
    nmrao
    Community Hero
    Are all the steps in each of the test case of the suite contains only Test Request steps only? If there are other steps then you have to filterout that condition to apply of if the step of certain type.
  • There are 3 types of test steps in each of my test case -

    test request
    groovy script
    properties
    property transfer

    but how does this affect "try - catch" block not working in "tear down" script ?
    Is it because "try-catch" only works with functions and i do not have any function in my tear down script?