围绕我的实际结果导致assert失败的SOAPUI方括号 [英] SOAPUI Square brackets around my actual results causing assert to fail

查看:145
本文介绍了围绕我的实际结果导致assert失败的SOAPUI方括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个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。响应)

//从jdbc响应获取预期结果
def expectedCodes = context.expand('$ {JDBC Request#ResponseAsXml#// *:TW304_PRODHIST.PRODUCT_1}')

//从SOAP响应获取实际结果
def actualCodes = pxml。'**'。findAll {it.name()=='CurrHospProductCode'} * .text()

assert expectedCodes == actualCodes

log.info expectedCodes
log.info actualCodes

$

解决方案

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

如果这是正确的,您可以如下所示:

  assert expectedCodes == actualCodes [0] 

在附注中,您可能需要检查仔细地说,你真的只期望单一的价值,或者如果有可能获得价值清单。



编辑:根据你的脚本。
findAll 会以列表形式显示结果。如果您期望xml中有单个元素,那么您可以将其更改为 find ,然后您的实际代码应该照原样运行。


I am writing a Groovy script assertion which is verifying a value from a previous JDBC response step against a value contained in a SOAP response.

When I run my scripts I can see that both values are coming back the same but the actual result value (from the SOAP response) is surrounded by square brackets which in turn makes the assert fail. I'm guessing this is something to do with one being a string and one not?

How do I either strip out the square brackets from actual result or get them added to the expected result value to ensure the assert passes?

Below is my assert script.

Expected result is 001 Actual result is [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

解决方案

Because you are expecting a single value as expected where as you are getting an array with single element in it.

You can do it as below if that is right :

assert expectedCodes == actualCodes[0]

On a side note, you may have to check carefully are you really expecting single value only or if there is possible to get list of values.

EDIT: based on your script. findAll gives you list as result. If you are expecting single element in the xml, then you can change it to find and then you actual code should work as it is.

这篇关于围绕我的实际结果导致assert失败的SOAPUI方括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆