SOAPUI中的Groovy声明重复位于预期数据的节点 [英] Groovy in SOAPUI Asserting on repeating nodes located by expected data
问题描述
下面是一个解释我的场景的示例响应
< ns2:Details xmlns:ns2 =http:// WW>
< ns2:代码> 011< / ns2:代码>
< ns2:结果> 4< / ns2:结果>
< / ns2:详情>
< ns2:Details xmlns:ns2 =http:// ww>
< ns2:代码> 018< / ns2:代码>
< ns2:结果> 0< / ns2:结果>
< / ns2:详情>
< ns2:Details xmlns:ns2 =http:// ww>
< ns2:代码> 098< / ns2:代码>
< ns2:结果> 2< / ns2:结果>
< / ns2:详情>
我感兴趣的测试数据包含在 ns2中:结果
。我已经知道在这个节点中我期待着什么值,但它必须与正确的 ns2:Code
值相关联。
例如,为了进行这个测试过程,我期望
- 期望
代码011
when结果是4
- 期望
代码018
when结果是0
依此类推。
所以我已经知道的数据是Code和结果,但我需要确保为每个代码返回正确的结果值。我不需要验证哪些代码被返回,我只需要根据正确的代码验证结果数字。
创建一个如下图所示的预期结果,它是 Code和Result
的组合,因此两者都可以一起验证/声明。
['011':'4','018':'0','098':'2']
在相同的请求测试步骤中使用脚本声明。
这里是脚本:
//如果有响应,则断言
assert context.response,'响应为空或空
//根据需要改变下图
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
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 correctns2:Code
value.For instance, to make this test pass I would expect
- expect
Code 011
whenResult is 4
- expect
Code 018
whenResult 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.
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
这篇关于SOAPUI中的Groovy声明重复位于预期数据的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!