gpt4 book ai didi

xml - SoapUI:在一个断言中有多个预期结果

转载 作者:行者123 更新时间:2023-12-03 16:58:00 25 4
gpt4 key购买 nike

有没有一种方法可以在一个测试步骤的一个声明中获得多个预期结果。

宣布:

declare namespace b="base"; //b:policies/b:policy/b:total-premium

预期结果:

7.362*

XML断言代码:

<con:assertion type="XPath Match" id="" name="XPath Match">                                             
<con:configuration>
<path>
declare namespace b="base"; //b:policies/b:policy/b:total-premium
</path>
<content>7.362*</content>
<allowWildcards>true</allowWildcards>
<ignoreNamspaceDifferences>false</ignoreNamspaceDifferences>
<ignoreComments>false</ignoreComments>
</con:configuration>
</con:assertion>
<con:credentials>
<con:authType>No Authorization</con:authType>
</con:credentials>
<con:jmsConfig JMSDeliveryMode="PERSISTENT"/>
<con:jmsPropertyConfig/>
<con:wsaConfig mustUnderstand="NONE" version="200508" action="" addDefaultTo="true"/>


我想SoapUI要做的是将此特定测试步骤的 total-premium值与 7.362*6.994*7.730*的值进行比较,如果它们中的任何一个通过了测试步骤,则通过。

那可能吗?

最佳答案

一种可行的方法是使用Script assertion代替Xpath match assertion

Script assertion中,您可以解析响应,获取节点值并与可能值的列表进行比较,例如:

// get the xml response
def response = messageExchange.getResponseContent()
// parse it
def xml = new XmlSlurper().parseText(response)
// find your node by name
def node = xml.'**'.find { it.name() == 'total-premium' }
// assert against the possible values
assert ['7.362*','6.994*','7.730*'].contains(node.toString())


更新资料

首先,我误解了您的问题,我想您想确切地检查 7.362*,实际上通配符是用于任何数字的,对不起。然后,您可以使用带有 matches()方法的正则表达式来检查您的值是否以某些所需值开头:

// get the xml response
def response = messageExchange.getResponseContent()
// parse it
def xml = new XmlSlurper().parseText(response)
// find your node by name
def node = xml.'**'.find { it.name() == 'total-premium' }
// assert
assert node.toString().matches("(7.362|6.994|7.730)\\d*")

关于xml - SoapUI:在一个断言中有多个预期结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39915398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com