cancel
Showing results for 
Search instead for 
Did you mean: 

SoapUI Teardown Script

go2khurram
Contributor

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())
    }
}
7 REPLIES 7
rupert_anderson
Valued Contributor

Re: SoapUI Teardown Script

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

Author of SoapUI Cookbook
nmrao
Community Hero

Re: SoapUI Teardown Script

Another variant to what Rup suggested is

if (testStep instanceof WsdlTestRequestStep) {
//do the stuff
}


Regards,
Rao.
go2khurram
Contributor

Re: SoapUI Teardown Script

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
Valued Contributor

Re: SoapUI Teardown Script

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

Author of SoapUI Cookbook
go2khurram
Contributor

Re: SoapUI Teardown Script

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>
rupert_anderson
Valued Contributor

Re: SoapUI Teardown Script

Ah! I see what you mean, its the property expansion that doesn't get substituted, I can reproduce the same now in my file..

 

Right now I'm not sure how to get the populated request, if I get a chance later I'll see if I can find another property that holds it - meanwhile if anyone else knows off-hand please jump in!

 

Thanks,

Rupert 

Author of SoapUI Cookbook
nmrao
Community Hero

Re: SoapUI Teardown Script

 

//Assuming that the name of the test step is "Test Request", and modify as needed
def request = context.expand('${Test Request#Request}')
log.info request

 If you already have testStep object(based on your existing code snippet) and do not like to use as above, then you may use as below

 

 

def tempRequestObject = "\${${testStep.name}#Request}"
def request = context.expand(tempRequestObject)
log.info request

Similarly, you may get the response too.

 

def tempReponseObject = "\${${testStep.name}#Response}"
def response = context.expand(tempResponseObject)
log.info response

 



Regards,
Rao.
New Here?
Join us and watch the welcome video:
Top Kudoed Authors