I'm trying to extract the header from a previous request in SoapUI so I can use it in another request. Basically, I want to get the node value for Header in one xml and insert it into the header value of another xml. I have tried using XMLSlurper and XMLParser but not getting exactly what I want. I can extract out the text from the nodes but need the actual whole header value so it can be inserted into other requests as needed.
text = testRunner.testCase.testSteps["ConversionRate"].testRequest.response.getRequestContent()
log.info text
def slurped = new XmlSlurper().parseText(text)
log.info slurped.Header
This results in Value1Value2 using the XML example below but I want to extract out the whole header so it looks like
<soapenv:Header>
<soapenv:MyTag>value1</soapenv:MyTag>
<soapenv:MyTag2>value2</soapenv:MyTag2>
</soapenv:Header>
Sample XML for the purpose of this question is below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:web="http://www.webserviceX.NET/">
<soapenv:Header>
<soapenv:MyTag>value1</soapenv:MyTag>
<soapenv:MyTag2>value2</soapenv:MyTag2>
</soapenv:Header>
<soapenv:Body>
<web:ConversionRate>
<web:FromCurrency>AFA</web:FromCurrency>
<web:ToCurrency>ALL</web:ToCurrency>
</web:ConversionRate>
</soapenv:Body>
</soapenv:Envelope>
Once I have the value I will need to insert it into the header as an xml sample such as below
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:web="http://www.webserviceX.NET/">
<soapenv:Header/>
<soapenv:Body>
<web:ConversionRate>
<web:FromCurrency>AFA</web:FromCurrency>
<web:ToCurrency>ALL</web:ToCurrency>
</web:ConversionRate>
</soapenv:Body>
</soapenv:Envelope>
Hope this makes sense and any suggestions on how to get the node value for Header in xml and insert it into the header value of another xml would be very appreciated
Thanks
You do not have use an addition groovy script to achieve the same. Instead add
Script Assertion
with the below code for the first SOAP request test step.Script: follow in-line comments
Make the following change in the next request where you wanted to add the headers. Note the headers and property expansions.
Based on the comments, adding the below as answer. And this is completely different solution from the other one.
Here is the Script Assertion (for the first test step): You may also follow the in-line comments.