Forum Discussion

vijaydi's avatar
vijaydi
Contributor
13 years ago

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.

4 Replies

  • jamonlysa's avatar
    jamonlysa
    New Contributor
    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. thank you!






    -------------------------------------------------------------------------------------------
    Rc Hobby|Remote Control Helicopter|Cheap Rc Helicopter
  • jamonlysa - Not sure what you are trying to get at.

    On each iteration based on the test data input, I will have to remove a particular node or certain nodes from the SoapRequest (It's the seconds part of my requirement).

    In order to achieve the second requirement, I have to first clone or copy the content of one SoapRequest (which does not change) to another, whr I can perform the delete operations.

    And the doubt asked is around cloning or copying of the content from one request to another.
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Why not just have the Groovy script remove the particular node from the initial request and use the results for the second request?

    Groovy script:

    def grUtils = new com.eviware.soapui.support.GroovyUtils(context)
    def ReqHolder = grUtils.getXmlHolder("Original#Request")

    def data = 'delete first name' // to decide which node to remove - this will be different for you

    if (data == 'delete first name') {
    ReqHolder.removeDomNodes('//idm:first-given-name')
    } else { // delete last name
    ReqHolder.removeDomNodes('//idm:family-name')
    }

    return ReqHolder.xml

    Second request:
    ${Groovy Script#result}
  • Thanks M McDonald. Much appreciate your response.

    Will give it a go.