SoapUI:在一个断言中有多个预期结果
SoapUI: have multiple expected results in one assertion
有没有一种方法可以在一个测试步骤的一个断言中获得多个预期结果。
声明:
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*")
如果您更喜欢 XPath 而不是 Groovy 脚本,您仍然可以使用简单的 XPath 表达式:
declare namespace b="base";
starts-with(//b:policies/b:policy/b:total-premium, '7.362') or
starts-with(//b:policies/b:policy/b:total-premium, '6.994') or
starts-with(//b:policies/b:policy/b:total-premium, '7.730')
预期的结果是 true。
借助 XPath,您可以像在其他编程语言中一样使用函数和运算符。
有没有一种方法可以在一个测试步骤的一个断言中获得多个预期结果。
声明:
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*")
如果您更喜欢 XPath 而不是 Groovy 脚本,您仍然可以使用简单的 XPath 表达式:
declare namespace b="base";
starts-with(//b:policies/b:policy/b:total-premium, '7.362') or
starts-with(//b:policies/b:policy/b:total-premium, '6.994') or
starts-with(//b:policies/b:policy/b:total-premium, '7.730')
预期的结果是 true。
借助 XPath,您可以像在其他编程语言中一样使用函数和运算符。