Forum Discussion

pankajmalinda's avatar
pankajmalinda
Occasional Contributor
7 years ago

Saving request and response

 

I want to save request and response of all the tests(Failed/Passed) from my Automation test suite.

The folder location should be like ProjectName-->TestSuiteName(Multiple folders for multiple test suite)-->TestCaseName(Multiple folder for multiple test cases)- a single .xml file containg request and response of test steps (Multiple files for multiple test steps).

  • richie's avatar
    richie
    7 years ago

    Hi pankajmalinda

     

    There's a groovy event handler that does this quite nicely - the following script will record the request and response for each test step as well as the pass/fail result for every test step, in every test case, in every test suite in a project.

     

    The event handler is 'TestRunListener.AfterStep'

     

    The script is as below:  

    def pName = context.currentStep.testCase.testSuite.project.name //get project name
    def pDate = new Date().format( 'yyyyMMdd' )//get current date
    def sDate = pDate.toString()//convert date to string
    def pTestSuite = context.currentStep.testCase.testSuite.name//get TestSuite name
    def pTestCase = context.currentStep.testCase.name//get TestCase name
    def filePath = 'C:/SoapUI Projects/TS0.1/TestEvidence/'+pName+'_'+sDate+'/'+pTestSuite+'/'+pTestCase+'/'//compose the folder path
    
    File file = new File(filePath)
    if (!file.exists()) file.mkdirs()//create the destination folder
    
    fos = new FileOutputStream(filePath+ testStepResult.testStep.label + '.txt', true)
    pw = new PrintWriter( fos )
    testStepResult.writeTo( pw )
    pw.close()
    fos.close()

     

    I think this is brilliant - can't claim it was my code - I found it somewhere on soapui.org - but it records everything!

     

    I use it as a way to capture my test evidence

     

    Hope this helps,

     

    richie

     

     

  • groovyguy's avatar
    groovyguy
    Community Hero

    Are you familiar with groovy scripting? That might be the easiest way to accomplish this.

    • richie's avatar
      richie
      Community Hero

      Hi pankajmalinda

       

      There's a groovy event handler that does this quite nicely - the following script will record the request and response for each test step as well as the pass/fail result for every test step, in every test case, in every test suite in a project.

       

      The event handler is 'TestRunListener.AfterStep'

       

      The script is as below:  

      def pName = context.currentStep.testCase.testSuite.project.name //get project name
      def pDate = new Date().format( 'yyyyMMdd' )//get current date
      def sDate = pDate.toString()//convert date to string
      def pTestSuite = context.currentStep.testCase.testSuite.name//get TestSuite name
      def pTestCase = context.currentStep.testCase.name//get TestCase name
      def filePath = 'C:/SoapUI Projects/TS0.1/TestEvidence/'+pName+'_'+sDate+'/'+pTestSuite+'/'+pTestCase+'/'//compose the folder path
      
      File file = new File(filePath)
      if (!file.exists()) file.mkdirs()//create the destination folder
      
      fos = new FileOutputStream(filePath+ testStepResult.testStep.label + '.txt', true)
      pw = new PrintWriter( fos )
      testStepResult.writeTo( pw )
      pw.close()
      fos.close()

       

      I think this is brilliant - can't claim it was my code - I found it somewhere on soapui.org - but it records everything!

       

      I use it as a way to capture my test evidence

       

      Hope this helps,

       

      richie