Forum Discussion

VGaur's avatar
VGaur
Contributor
10 years ago

Print raw request and response in stack trace on test case failure

Hello Peeps, 

 

I want to print the raw request and response in the stack trace when a test case fails.How can I do that??

 

Cheers,

Varun

  • Noticed this question as part of August News Journal. At times it is possible to miss some question. Thanks for the journal for better followup.

     

    Here is the script that can used in Tear Down for test case.

     

    import com.eviware.soapui.model.testsuite.TestRunner.Status
    
    def logRawData = { stepName ->
    	def step = testRunner.testCase.getTestStepByName(stepName)
         def rawRequest = new String(step.testRequest.messageExchange.rawRequestData)
         def rawResponse = new String(step.testRequest.messageExchange.rawResponseData)
         log.error rawRequest
         log.error rawResponse	
    }
    
    if (testRunner.status == Status.FAILED) {
    //You need to provide the request step name and you can repeat the same 
    //statement with different step name in case of multiple steps for a test case logRawData('Test Request1') logRawData('Test Request2') }

    Hope this is useful

1 Reply

  • nmrao's avatar
    nmrao
    Champion Level 3

    Noticed this question as part of August News Journal. At times it is possible to miss some question. Thanks for the journal for better followup.

     

    Here is the script that can used in Tear Down for test case.

     

    import com.eviware.soapui.model.testsuite.TestRunner.Status
    
    def logRawData = { stepName ->
    	def step = testRunner.testCase.getTestStepByName(stepName)
         def rawRequest = new String(step.testRequest.messageExchange.rawRequestData)
         def rawResponse = new String(step.testRequest.messageExchange.rawResponseData)
         log.error rawRequest
         log.error rawResponse	
    }
    
    if (testRunner.status == Status.FAILED) {
    //You need to provide the request step name and you can repeat the same 
    //statement with different step name in case of multiple steps for a test case logRawData('Test Request1') logRawData('Test Request2') }

    Hope this is useful