Ask a Question

how to import xmls and save responses

tammasarath
New Contributor

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
7 REPLIES 7
tammasarath
New Contributor

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.
singhtester
Contributor

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
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')
}
"Ignorance more frequently begets confidence than does knowledge"
singhtester
Contributor

M McDonald, very well explained.
Ashik
Occasional Contributor

Hi,
how to add the request step script you mentioned.....just pasting the given script doesnt work...

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cal="http://www.parasoft.com/wsdl/calculator/">
<soapenv:Header/>
<soapenv:Body>
<cal:add>
<cal:x>?</cal:x>
<cal:y>?</cal:y>
</cal:add>
</soapenv:Body>
</soapenv:Envelope>

This is my actual xml request which i need to fetch....
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}


@Ashik wrote:
Hi,
how to add the request step script you mentioned.....just pasting the given script doesnt work...

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/essaytyper" xmlns:cal="http://www.parasoft.com/wsdl/calculator/">
<soapenv:Header/>
<soapenv:Body>
<cal:add>
<cal:x>?</cal:x>
<cal:y>?</cal:y>
</cal:add>
</soapenv:Body>
</soapenv:Envelope>

This is my actual xml request which i need to fetch....

Hi! I wanted to ask if you figured out how to make the script work?

cancel
Showing results for 
Search instead for 
Did you mean: