Forum Discussion

testbaer's avatar
13 years ago

Modify SOAP Request dinamically

I want to create a script that modifies a SOAP request dynamically so I can automate my tests. I'm new to Groovy and SOAP UI and I'm a bit lost. My initial idea would be to modify with a script the Custom Property "Request" from the SOAP Request. I've been playing around with XmlParser and XmlSlurper but can't make work to navigate my XML structure and then edit or add an entry in the proper way. My structure is something like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:par="">
<soapenv:Header/>
<soapenv:Body>
<par:"">
<settings>
<label1>
<entry>
<key></key>
<value></value>
</entry>
</label1>
<label 2></label2>
<label3>
<value1></value1>
<value2></value2>
<value3></value3>
</label3>
</settings>
</par:"">
</soapenv:Body>
</soapenv:Envelope>´

For example I would like to add an additional label3 after the one that is already there with new values.
Any hints or help will be greatly appreciated

1 Reply

  • You could look at the MarkUpBuilder (see here See Example 8:)

    Example
    def sw = new StringWriter()
    def xml = new groovy.xml.MarkupBuilder(sw)
    xml.'soapenv:Envelope'( 'xmlns:soapenv' : "http://schemas.xmlsoap.org/soap/envelope/", 'xmlns:par' : "") {
    'soapenv:Header' {}
    'soapenv:Body' {
    'par:""' {
    'settings' {
    'label1' {
    'entry' {
    'key' 'hiho'
    'value' {}
    }
    }
    'label2' {}
    'label3' {
    'value1' {}
    'value2' {}
    'value3' {}
    }
    }
    }
    }
    }
    log.info sw


    will get you this


    <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:par=''>
    <soapenv:Header />
    <soapenv:Body>
    <par:"">
    <settings>
    <label1>
    <entry>
    <key>hiho</key>
    <value />
    </entry>
    </label1>
    <label2 />
    <label3>
    <value1 />
    <value2 />
    <value3 />
    </label3>
    </settings>
    </par:"">
    </soapenv:Body>
    </soapenv:Envelope>