Reputation: 13
I am very new to SoapUI (open source version) and REST. We have an ERP system that uses REST via web services to allow third part applications to communicate with it. I am using SoapUI to test out how these calls work. I use a user name & password to get a token for my session. I've used the Property Transfer inside SoapUI to set the user name & password. The result is in XML:
<MGRestTokenResponse xmlns="http://schemas.datacontract.org/2004/07/" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Message>success</Message>
<Token>--I WANT THIS DATA--</Token>
</MGRestTokenResponse>
When I used the Property Transfer to get the token, the best I could get is to store the entire XML output. After a lot of Googling, the only solution I could come up with is in a follow up step, use the following Groovy code:
def content = context.expand('${Set Test Properties#sectoken}')
def xml = new XmlSlurper().parseText(content)
def token = xml.getAt("Token")
testRunner.testCase.getTestStepByName("Set Test Properties").setPropertyValue("sectoken",token.toString())
Is this the correct/preferred way to extract data from an XML response in SoapUI? Should I have done anything with the text field below the "Target" settings? I assume that the process would be similar with JSON (swapping the Slurper our for Json).
I've got a lot of testing I need to use SoapUI from & I want to be sure I'm using the tool properly.
Upvotes: 1
Views: 2033
Reputation: 3891
Yes you found it right, There are 2 ways of fetching data.
a) XmlParser/XmlSlurper
b) xmlHolder
Also please note that if your xml has namespaces, then only xmlHolder can help you.
i.e. <f:table>
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
<f:table>
i.e. //*:length will still remain valid, but if you use xml.getAt(length) this may not work
def groovyUtils= new com.eviware.soapui.support.GroovyUtils(context)
def xml=groovyUtils.getXmlHolder('YourRestRequestName#Request')
def token=xml.getNodeValue("//*:Token")
log.info token
and the correct syntax for fetching value via Property transfer step is
declare namespace ns1='http://schemas.datacontract.org/2004/07/';
//ns1:MGRestTokenResponse[1]/ns1:Token[1]
Using groovy is more benefical as it makes your task very easy if you want so many validation.
Upvotes: 2
Reputation: 2417
This should be possible with the property transfer test step. The reason I bring this up is that I find that is it less taxing on the system memory than groovy scripts.
The below should be able to transfer the property you are looking for provided you have added a properties test step.
Please let me know if this helps
Upvotes: 3