Forum Discussion

go2khurram's avatar
go2khurram
Contributor
9 years ago

SoapUI Teardown Script

I have found the below teardown script from one the blog to save the request and response in to a folder /files.

It works fine when  I have only SOAP request steps but did not work for other types of steps. I have property transfer, groovt script, JDBC Request, Delay and SOAP request in my steps , but only intrested to record request and response of SOAP Request.

// path for the testSuite
def folderPath =  'C:/temp/' + testSuite.name + '_' + System.currentTimeMillis() + File.separator
new File(folderPath).mkdirs()

// for each testCase in the testSuite
testSuite.testCases.each { testCaseName, testCase ->

    // path for this testCase
    def folderPathSuite = folderPath + testCaseName + File.separator
    new File(folderPathSuite).mkdir()

    // for each testStep
    testCase.testSteps.each { testStepName, testStep ->
        // define a file 
        def file = new File(folderPathSuite + testStepName + '_response.xml')
        // get the response and write to file
        file.write(testStep.getProperty('Response').getValue())
    }
}
  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    Is it that you want to skip non SOAP TestSteps in your script, dumping just the SOAP ones? Like this:

     

    import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
    
    def folderPath =  '/temp/' + testSuite.name + '_' + System.currentTimeMillis() + File.separator
    new File(folderPath).mkdirs()
    
    // for each testCase in the testSuite
    testSuite.testCases.each { testCaseName, testCase ->
    
        // path for this testCase
        def folderPathSuite = folderPath + testCaseName + File.separator
        new File(folderPathSuite).mkdir()
    
        // for each testStep
        testCase.testSteps.each { testStepName, testStep ->
        	log.info testStep.class
        	if (testStep.class == WsdlTestRequestStep){
            // define a file 
            def file = new File(folderPathSuite + testStepName + '_response.xml')
            // get the response and write to file
            file.write(testStep.getProperty('Response').getValue())
        	}
        }
    }
    

    Thanks,

    Rupert

    • nmrao's avatar
      nmrao
      Champion Level 3
      Another variant to what Rup suggested is

      if (testStep instanceof WsdlTestRequestStep) {
      //do the stuff
      }
  • Thanks Rao and Rupert, 

     

    I realy appriciate your response on this. I have supliment question. Actiually I am also storing the request along with the response by using the below code you suggested. But in my request xml , it store the path of custome properties instead of actual value used in the request. Is there anyway I could save the request with actual data. thanks in advanve for your help.

     

    import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep
    
    def folderPath =  'D:/TearDown/' + testSuite.name + '_' + System.currentTimeMillis() + File.separator
    new File(folderPath).mkdirs()
    
    // for each testCase in the testSuite
    testSuite.testCases.each { testCaseName, testCase ->
    
        // path for this testCase
        def folderPathSuite = folderPath + testCaseName + File.separator
        new File(folderPathSuite).mkdir()
    
        // for each testStep
        testCase.testSteps.each { testStepName, testStep ->
        	log.info testStep.class
        	if (testStep.class == WsdlTestRequestStep){
            // define a file 
            def file1 = new File(folderPathSuite + testStepName + '_request.xml')
    	def file2 = new File(folderPathSuite + testStepName + '_response.xml')
            // get the response and write to file
    	file1.write(testStep.getProperty('Request').getValue())        
    	file2.write(testStep.getProperty('Response').getValue())
        	}
        }
    }
    • rupert_anderson's avatar
      rupert_anderson
      Valued Contributor

      Hi,

       

      No problem, happy to have helped!

       

      Your script (with the request logging) seems to work fine to me? I get a file _request.xml created containing the request XML.

       

      Can you show me what you get instead?

       

      Thanks,

      Rup

      • go2khurram's avatar
        go2khurram
        Contributor

        Thanks again, This is the request file stored in my case. CLI tage should have proper telephone number 

        <OrderLookupRequestInput>
                <CLI>${#TestCase#CLI}</CLI>
                <EarlyDaysDuration>0</EarlyDaysDuration>
                <EarlyDaysThreshold>0</EarlyDaysThreshold>
                <EarlyDaysHours>0</EarlyDaysHours>
                <InLifeDaysDuration>0</InLifeDaysDuration>
                <InLifeDaysThreshold>0</InLifeDaysThreshold>
                <InLifeDaysHours>0</InLifeDaysHours>
                <CancelledDays>0</CancelledDays>
              </OrderLookupRequestInput>