Forum Discussion

skelkar's avatar
skelkar
Contributor
11 years ago

How to log RequestIds for all failed test steps

Hi,

I would like to capture and log requestIds of all failed test steps from all test cases in a test suite.
Any idea how to achieve that.

I tried adding below script into test suite tear down script but no luck.
for ( testCaseResult in runner.results )
{
testCaseName = testCaseResult.getTestCase().name
log.info testCaseName
if ( testCaseResult.getStatus().toString() == 'FAILED' )
{

for ( testStepResult in testStepResult.getResults() )
{

if ( testStepResult.getStatus().toString() == 'FAILED' )
{

testStepName = testStepResult.getTestStep().name
log.info testStepName

String ReqId = testRunner.testCase.testSteps[testStepName].testRequest.response.responseHeaders["RequestId"]
ReqId=ReqId.replaceAll("\\[", "")
ReqId=ReqId.replaceAll("\\]", "")

log.info "ReqId : " + ReqId
}
}
}
}

Please advise.

Suraj

4 Replies

  • Hi,

    Try the following script and fill in where needed.


    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
    }
    }
    }//end if
    }//end for



    Regards,
    Marcus
    SmartBear Support
  • Hi,

    I put it ithis script in test suite tear down script area but not able to log requestids of failed test steps.
    May be the request id capturing script I added having issues, have a look .

    or ( 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().name
    // log.info testStep
    //do what needs to be done here to get the response content for the testStep

    //*******my script to log the requestId of each failed test step**************

    String ReqId = testRunner.testCase.testSteps[testStep].testRequest.response.responseHeaders["RequestId"]

    log.info "failed test step: "+ testStep+" RequestId is :"+ ReqId
    log.info "requestid of failed step is :"+ReqId

    //*******my script to log the requestId of each failed test step**************
    }
    }
    }//end if
    }//end for
  • Hi,

    Replace
    String ReqId = testRunner.testCase.testSteps[testStepName].testRequest.response.responseHeaders["RequestId"]
    with
    def ReqId = testStep.testRequest.response.responseHeaders["RequestId"].get(0)


    That will get the value of the RequestId header, in which you can modify afterwards.


    Regards,
    Marcus
    SmartBear Support
  • Hey,

    Thanks it worked.
    Now I am trying to create a .txt folder at suite level on my drive with info of only failed test steps from each failed case.
    Will ask more help if I am stuck anywhere.