How to generate requests and responses for all operations of a WSDL in soapUI using a groovy script

groovysoapuiwsdl

I have a WSDL which has multiple operations. For each op i want a template .xml with its response and request.

I know how to do this manually in soapUI but I would like to generate them using a groovy script.
I googled a lot already, but seems I'm the only one who is looking for this.

My service has 16 Operations, so to do this manual would be too much time. Since the service gets updates every 2 months, an automation using a test step would be perfect.

I managed to do it for the requests already:

right-click on ´services´ in left tree, ´Generate Test Suite´, ´Single Test Case with one Request for each Operation´

then I loop through those Test Step Requests and store them on my disk.

    import com.eviware.soapui.impl.wsdl.teststeps.*

    for( testCase in testRunner.testCase.testSuite.getTestCaseList() ) 
    {
        for( testStep in testCase.getTestStepList() ) 
        {
            if( testStep instanceof WsdlTestRequestStep ) 
            {
                log.info "operation name: " +testStep.getName()

                // create file name
                Date startTime = new Date();
                def cur_Time = startTime.getMonth() + "_" + startTime.getDate();
                cur_Time = cur_Time + "_" + startTime.getHours() + startTime.getMinutes() +startTime.getSeconds()
                def fileName = testStep.getName() + "_" + cur_Time

                def inputFileRequest = new File("T:\\"+ "Request_" + fileName+".txt")
                def inputFileResponse = new File("T:\\"+ "Response_" + fileName+".txt")
                // write request to file
                inputFileRequest.write(testStep.getProperty("request").value)
            }
        }
    }

But I havent figured out a way to do this also for the resposes.
If i use getProperty("reponse") it's null of course.

Any hint? 🙂

Best Answer

and the winner is, I figured it out myself:

map = context.testCase.testSuite.project.interfaces["services"].operations

for (entry in map)
{
    opName = entry.getKey()
    inputFileRequest = new File("T:\\" + opName + "Request.xml")
    inputFileResponse = new File("T:\\" + opName + "Response.xml")

    inputFileRequest.write(entry.getValue().createRequest(true))
    inputFileResponse.write(entry.getValue().createResponse(true))
}
Related Topic