SOAPUI方括号围绕我的实际结果导致断言失败

时间:2017-09-28 02:00:12

标签: groovy soapui assert

我正在编写一个Groovy脚本断言,该断言正在验证先前JDBC响应步骤中的值与SOAP响应中包含的值。

当我运行我的脚本时,我可以看到两个值都返回相同但实际结果值(来自SOAP响应)被方括号包围,这反过来使断言失败。我猜这是一个字符串而不是一个字符串?

如何从实际结果中删除方括号或将它们添加到预期结果值以确保断言通过?

以下是我的断言脚本。

预期结果为001 实际结果为[001]

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder( messageExchange.responseContent )
def pxml = new XmlSlurper().parseText(context.response)

//grab the expected result from jdbc response
def expectedCodes = context.expand( '${JDBC Request#ResponseAsXml#//*:TW304_PRODHIST.PRODUCT_1}' ) 

//grab the actual result from the SOAP response
def actualCodes = pxml.'**'.findAll{it.name() == 'CurrHospProductCode'}*.text() 

assert expectedCodes == actualCodes

log.info expectedCodes
log.info actualCodes

1 个答案:

答案 0 :(得分:2)

因为您希望获得单个值,因为您将获得包含单个元素的数组。

如果这是正确的,您可以按照以下方式执行:

assert expectedCodes == actualCodes[0]

在旁注中,您可能需要仔细检查您是否真的只期望单值或者是否有可能获得值列表。

编辑:根据您的脚本。 findAll为您提供结果列表。如果您希望xml中有单个元素,那么您可以将其更改为find,然后您的实际代码应该按原样运行。

相关问题