Reputation: 501
Below is an example response to explain my scenario
<ns2:Details xmlns:ns2="http://ww">
<ns2:Code>011</ns2:Code>
<ns2:Result>4</ns2:Result>
</ns2:Details>
<ns2:Details xmlns:ns2="http://ww">
<ns2:Code>018</ns2:Code>
<ns2:Result>0</ns2:Result>
</ns2:Details>
<ns2:Details xmlns:ns2="http://ww">
<ns2:Code>098</ns2:Code>
<ns2:Result>2</ns2:Result>
</ns2:Details>
The data that I am interested in testing here is contained in ns2:Result
. I already know what value I am expecting in this node, but it has to be associated with the correct ns2:Code
value.
For instance, to make this test pass I would expect
Code 011
when Result is 4
Code 018
when Result is 0
and so on.So the data I already know is Code and Result, but I need to ensure that the correct Result values are being returned for each Code. I don't need to verify what Code's are returned, I just need to verify the Result figures against the correct Codes.
Upvotes: 1
Views: 289
Reputation: 21379
Create an expected result as a map as below which is combination of Code and Result
, so that both can be verified / asserted together.
['011': '4', '018': '0', '098': '2']
Use Script Assertion for the same request test step.
Here goes the script:
//assert if there is response
assert context.response, 'Response is null or empty
//change below map as needed
def expected = ['011': '4', '018': '0', '098': '2']
def xml = new XmlSlurper().parseText(context.response)
def actual = xml.'**'.findAll{it.name() == 'Details'}.collectEntries{[(it.Code.text()): it.Result.text()]}
assert expected == actual
Upvotes: 3