I am using Ready API/SOAP UI. I added a SOAP request and I get a SOAP response XML. My response object has up to 40 Key/Value pairs.
I have functional tests to specifically test each.
- Loop through the whole ArrayOfObjects and Assert if the Key exists and if it exists assert the value.
Can I get a working solution for this scenario. I am unable to do assert on the output object.
SOAP structure looks like this:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<ArrayOfallObjects>
<ArrayOfObjects>
<Key>Key1</Key>
<Value>Value1</Value>
</ArrayOfObjects>
<ArrayOfObjects>
<Key>Key2</Key>
<Value>Value2</Value>
</ArrayOfObjects>
---------------
<ArrayOfObjects>
<Key>Key40</Key>
<Value>Value40</Value>
</ArrayOfObjects>
</ArrayOfallObjects>
</soap:Body>
</soap:Envelope>
And I am using groovy script snippet as below
//Code Snippet Starts//
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def request = context.testCase.getTestStepByName("RequestName")
def responseCurrentHolder = groovyUtils.getXmlHolder( request.name +"#Response")
responseCurrentHolder.namespaces["ns1"] = "https://test.com"
def nodes = responseCurrentHolder.getDomNodes( "//ns1:Response/ns1:Result/ns1:ArrayOfallObjects/ns1:ArrayOfObject/*" )
def nodeCount = responseCurrentHolder.getNodeValues("//ns1:Response/ns1:Result/ns1:ArrayOfallObjects/ns1:ArrayOfObject/ns1:Key").length
def object = [:]
for (def nodeIndex = 1; nodeIndex <= nodeCount; nodeIndex++) {
def nodeKey = responseCurrentHolder.getNodeValues("//ns1:Response/ns1:Result/ns1:ArrayOfallObjects/ns1:ArrayOfObject[$nodeIndex]/ns1:Key/text()")
def nodeValue = responseCurrentHolder.getNodeValue("//ns1:Response/ns1:Result/ns1:ArrayOfallObjects/ns1:ArrayOfObject[$nodeIndex]/ns1:Value/text()")
object.put( nodeKey,nodeValue)
}
log.info "Object =" +object
// Code snippet ends//
And the object looks like:
Object =[[Key1]:Value1, [Key2]:Value2, and so on upto --,[Key40]:Value40]