skelkar
11 years agoContributor
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.
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.