Matt
Matt

Reputation: 501

SOAPUI Square brackets around my actual results causing assert to fail

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

Upvotes: 2

Views: 1094

Answers (1)

Rao
Rao

Reputation: 21379

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.

Upvotes: 3

Related Questions