0

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.

Community
  • 1
  • 1
Jerry Penner
  • 111
  • 5

2 Answers2

1

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.

Jerry Penner
  • 111
  • 5
0

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.

Abhishek Asthana
  • 1,857
  • 1
  • 31
  • 51
  • I am using an XPath Match query. New information: The data in question always includes a comma in the data. ie: "123, Any St." Removing the quotes from the assertion data results in this message: XPathContains comparison failed, expecting [123, Any St.], actual was ["123, Any St."] Your code works well for a static assertion, but I need to pull the assertion data from a CSV datasource. I have zero experience with Groovy. How do I specify a datasource within your script? – Jerry Penner Aug 21 '13 at 16:15
  • Are you using soapUI Pro or opensource? the code i provided will work irrespective of what you have in the response XML. If you parameterize the expected value the my example will work for what you need. As this is an assertion it is not a good idea to mention the data source here. – Abhishek Asthana Aug 21 '13 at 16:37
  • I am using SoapUI Pro V 4.5.2. I can add the XPath of the response to your script and it works fine when I compare against a static value. I need to pull the expected value from a Data Source CSV and compare that to the XML response. Being a total n00b to Groovy, how do I specify my data source within your script? Alternately, is there a way to do this without scripting? – Jerry Penner Aug 21 '13 at 17:59
  • This script worked: ` 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 trick was to locate the datasource entry and use .replaceAll() to trim the 3X double quotes to 1X double quote before asserting. – Jerry Penner Aug 21 '13 at 19:14
  • Can you please add that as an answer? Its very difficult to ready code in a comment. – Abhishek Asthana Aug 21 '13 at 23:18