Jerry Penner
Jerry Penner

Reputation: 111

SoapUI Escaped Quotes Cause Assertion Failures

In SoapUI Pro V 4.5.2 I have created a data-driven test using an HTTP Test Request and a CSV file, tab-delimited, text is unquoted. Request is HTTP, response is XML. The data contains input variables and assertions for each response in the DataSource. Some of my assertions contain double quotes, ie: "123 Any St."

When I run the assertion I get a response of: XPathContains comparison failed, expecting ["""123, Any St."""], actual was ["123, Any St."]

My question is similar to this one: Xpath matches with single quotes?

but I am not using XSLT-based verification, I am using the XPath Match assertion in the HTTP Request.

The question is, how do I either disable the triple double quotes, work around them in the context of an HTTP request, or add something to my assertion data to make these assertions pass? Note that removing the double quotes from the response and thus the assertion data is not an option.

Upvotes: 0

Views: 2414

Answers (2)

Jerry Penner
Jerry Penner

Reputation: 111

Here is the code that did the trick:

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

    def holder = groovyUtils.getXmlHolder(messageExchange.responseContentAsXml)

    String val = holder.getNodeValue('//Location[1]/Address[1]/Line1[1]')

    def addressLine1 = context.expand( '${DataSource#AddressLine1}' )

    def vala = val.replaceAll('"""','"')

    def addressLine1a = addressLine1.replaceAll('"""','"')

    assert addressLine1a == vala, 'Assertion failed'

The replaceAll command is a string manipulation that trims any 3X double quotes to a 1X double quote before the assertion.

Upvotes: 1

Abhishek Asthana
Abhishek Asthana

Reputation: 1855

What kind of assertion are you using? Have you tried a script assertion or removing the quotes from your expected assertion value?

Can you please share the xml or the piece of xml which has the string in quotes?

Try this as a script assertion

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)

def holder = groovyUtils.getXmlHolder(messageExchange.responseContentAsXml)

String val = holder.getNodeValue('xPath to the value you want to extract')

assert 'The expected value in quotes' == val, "Appropriate message if the assertion fails"

The OP needs to be able to pick the expected value from a csv and compare it with what was received in the response.

As you are using the pro version of soapUI use the datasource to fetch the values from your csv file. Lets consider that your csv has a column called expectedVal which will contain the expected response value. This value can be anything, a xml, a quoted string, anything. Then our script assertion will change to below code

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = groovyUtils.getXmlHolder(messageExchange.responseContentAsXml)

String val = holder.getNodeValue('//ns1:GetConversionRateResponse[1]/ns1:GetConversionRateResult[1]/a:Rate[1]')
def expVal = context.expand( '${DataSource#expVal}' )

assert expVal == val, "Appropriate message if the assertion fails"

I have created a soapUI project using the currencyConversion service available at xmethods.net this project is a simple implementation of what i have explained below.

https://drive.google.com/folderview?id=0B7mJBdNSSV-YMW5jSFh3NGd1UHM&usp=sharing

The link above will be available for two days and you should really mark this as the answer.

Upvotes: 0

Related Questions