vijaydi
13 years agoContributor
How to copy the content of one soap request to another.
Hi All,
I am a newbie to groovy scripting and from a testing background.
My requirement is that, on each iteration based on the test data input, I will have to remove a particular node or certain nodes from the SoapRequest. In order to achieve that I created two identical SOAP Request -Original and Modified.
Using groovy script I am trying to restore the content of the modified soap request with the content of the original soap request after each iteration. (Iteration 1 - Node to delete is <idm:family-name> and in second iteration node to delete is <idm:first-given-name> keeping <idm:family-name> - This is the reason for restoring the request with the original content)
The below are my Teststeps under my TestSuite.
- Datasource
- Original (SoapRequest)
- Groovy Script.
- Modified (SoapRequest)
SoapRequest (Original)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:idm="http://vedaxml.com/vxml2/idmatrix-v2-0.xsd">
<soapenv:Header/>
<soapenv:Body>
<idm:request>
<idm:dataset-searches>
<idm:profile-name></idm:profile-name>
</idm:dataset-searches>
<idm:individual-name>
<idm:family-name>ABC</idm:family-name>
<idm:first-given-name>DEF</idm:first-given-name>
</idm:individual-name>
<idm:date-of-birth>1985-12-12</idm:date-of-birth>
</idm:request>
</soapenv:Body>
</soapenv:Envelope>
My Groovy Script is as below
def grUtils = new com.eviware.soapui.support.GroovyUtils(context)
def ReqHolder2 = grUtils.getXmlHolder("Modified#Request")
ReqHolder2.removeDomNodes("//idm:request")
ReqHolder2.updateProperty()
ReqHolder2 ["//soapenv:Body"] = context.expand( '${Original#Request#//idm:request}' )
ReqHolder2.updateProperty()
When I execute the above groovy script, the Modified request is updated with the content from the Original request but with <![CDATA[ and reference to the schema (I have highlighted in Red)
SoapRequest (Modified)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:idm="http://vedaxml.com/vxml2/idmatrix-v2-0.xsd">
<soapenv:Header/>
<soapenv:Body><![CDATA[<idm:request xmlns:idm="http://vedaxml.com/vxml2/idmatrix-v2-0.xsd">
<idm:dataset-searches>
<idm:profile-name/>
</idm:dataset-searches>
<idm:individual-name>
<idm:family-name>ABC</idm:family-name>
<idm:first-given-name>DEF</idm:first-given-name>
</idm:individual-name>
<idm:date-of-birth>1985-12-12</idm:date-of-birth>
</idm:request>]]></soapenv:Body>
</soapenv:Envelope>
I would greatly appreciate if someone could help me with this. Also, I would be glad to know/learn other alternative ways in grrovy to implement this requirement.
Thank you.
I am a newbie to groovy scripting and from a testing background.
My requirement is that, on each iteration based on the test data input, I will have to remove a particular node or certain nodes from the SoapRequest. In order to achieve that I created two identical SOAP Request -Original and Modified.
Using groovy script I am trying to restore the content of the modified soap request with the content of the original soap request after each iteration. (Iteration 1 - Node to delete is <idm:family-name> and in second iteration node to delete is <idm:first-given-name> keeping <idm:family-name> - This is the reason for restoring the request with the original content)
The below are my Teststeps under my TestSuite.
- Datasource
- Original (SoapRequest)
- Groovy Script.
- Modified (SoapRequest)
SoapRequest (Original)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:idm="http://vedaxml.com/vxml2/idmatrix-v2-0.xsd">
<soapenv:Header/>
<soapenv:Body>
<idm:request>
<idm:dataset-searches>
<idm:profile-name></idm:profile-name>
</idm:dataset-searches>
<idm:individual-name>
<idm:family-name>ABC</idm:family-name>
<idm:first-given-name>DEF</idm:first-given-name>
</idm:individual-name>
<idm:date-of-birth>1985-12-12</idm:date-of-birth>
</idm:request>
</soapenv:Body>
</soapenv:Envelope>
My Groovy Script is as below
def grUtils = new com.eviware.soapui.support.GroovyUtils(context)
def ReqHolder2 = grUtils.getXmlHolder("Modified#Request")
ReqHolder2.removeDomNodes("//idm:request")
ReqHolder2.updateProperty()
ReqHolder2 ["//soapenv:Body"] = context.expand( '${Original#Request#//idm:request}' )
ReqHolder2.updateProperty()
When I execute the above groovy script, the Modified request is updated with the content from the Original request but with <![CDATA[ and reference to the schema (I have highlighted in Red)
SoapRequest (Modified)
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:idm="http://vedaxml.com/vxml2/idmatrix-v2-0.xsd">
<soapenv:Header/>
<soapenv:Body><![CDATA[<idm:request xmlns:idm="http://vedaxml.com/vxml2/idmatrix-v2-0.xsd">
<idm:dataset-searches>
<idm:profile-name/>
</idm:dataset-searches>
<idm:individual-name>
<idm:family-name>ABC</idm:family-name>
<idm:first-given-name>DEF</idm:first-given-name>
</idm:individual-name>
<idm:date-of-birth>1985-12-12</idm:date-of-birth>
</idm:request>]]></soapenv:Body>
</soapenv:Envelope>
I would greatly appreciate if someone could help me with this. Also, I would be glad to know/learn other alternative ways in grrovy to implement this requirement.
Thank you.