Forum Discussion

tammasarath's avatar
tammasarath
New Contributor
12 years ago

how to import xmls and save responses

Hi guys,
my client is using soap UI, not soapUI pro. There are hundreds of XMLs which i have to load them into Soap UI and execute those requests(API testing). Can some one pls let me know how to import all/chunks of xmls at a time without copying and pasting each one at a time?
And also once i run a request(execute an xml request from the test suite) and get the resonse back, how can i save those responses?
I could not find any options for these two things in SOAP UI.
Your help is much appreciated.
Thanks,
Sarath
  • Come on guys, any help would be much appreciated. Copying and pasting XMLs one by one from Altova XML spy to Soap UI is not easy at all.
  • Sarath,

    1.I have not yet done, but there could be a "package" that you can create in what ever the tool you are having your XML in. Soapui can import the packages.Please share, in case you are able to do so.

    2.You can Save the response using the below:Create a groovy script with the below code.

    def myOutFile = "D:/outfiles/response.xml"
    def response = context.expand( '${Scriptname#Response}' )
    def f = new File(myOutFile)
    f.write(response, "UTF-8")

    Note:script name is your script name.

    Gurpreet
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    You have to use Groovy scripts to do this in SoapUI free version. Get a list of file names then submit contents of each file in the request step.

    First Groovy step to get list of files:

    def fileList = []
    new File("C:\\requests").eachFile { f ->
    if (f.isFile() && f.name.endsWith('.xml')) {
    def filename = f.name[0..-5]
    fileList.add(filename)
    }
    }
    if (fileList.size() < 1) {
    testRunner.fail("No request files")
    }
    context.put('fileList', fileList)

    Followed by request step with this in the body:

    ${=new File("C:\\requests\\" + (context.get('fileList')).last() +".xml").text}


    Followed by another Groovy step to remove the file from the list, write the response to a file and loop back to the request as long as there are more files:

    def fileList = context.get('fileList')
    def fileName = fileList.pop()
    def response = context.expand( '${Test Request#Response}' )
    def f = new File("C:\\responses\\${fileName}_Response.xml")
    f.write(response, "UTF-8")

    if (fileList.size() > 0) {
    testRunner.gotoStepByName('Test Request')
    }
  • Ashik's avatar
    Ashik
    Occasional Contributor
    hi,
    how to run this script in the request test step..
    ..please let me knw
    ${=new File("C:\\requests\\" + (context.get('fileList')).last() +".xml").text}