Ask a Question

Wild card in Contains assertion

New Contributor

Wild card in Contains assertion

I have lot of "contains" assertions in my scripts. like assertion content as  <ns3:rte>100</ns3:rte>


But unfortunately because of schema changes ,namespace prefix have changed.I have to change ns3 to ns4.And chances are there it may change again to ns7 or ns10 in future


Can I use wild care for namespace prefix  like <*:rte>100</*:rte>  or please tell me how I can use regular expression in contains assertion

Community Hero

With Contains, if you select regular expression, then there needs to be a complete match to the whole response body, so something like::



Rather than using contains, use XPath or another type of assertion (script assertion?)


When you use XPath and declare the namespaces, the prefixes are yours to make up (or let SoapUI make them up for you), and then those declarations are responsible for mapping the prefixes to the right namespaces. So even if more namespaces are added, as long as you don't change your declarations, then your existing assertions will still work.



And as for script assertions, the default when using XmlSlurper is to ignore namespaces and just assume there's no conflicts.



assert new XmlSlurper()
.find {it == '100'} == true




I have checked "Use token as regular expression".But even then if I use regular expression in contains assertion, it is not working

Community Hero

OK, I discovered that the Contains assertion uses




i.e. java's String.matches(String), and the default RegEx behaviour for Java is different to Groovy:



String content = '''
<soapenv:Envelope xmlns:soapenv=""
xmlns:sam=""> <soapenv:Header/> <soapenv:Body> <sam:buyResponse> <sam:buyResponseContent> <purchasestatus> <rte>100</rte> <stockStatus>?</stockStatus> <expectedDelivery>?</expectedDelivery> </purchasestatus> </sam:buyResponseContent> </sam:buyResponse> </soapenv:Body> </soapenv:Envelope>''' String replToken = /.*rte.*/ "java: ${content.matches(replToken)}, groovy: ${(content =~ replToken).find()}"
java: false, groovy: true

The difference is in whether . matches to newline character. You can specify that it should in your Regex with (?s):


String replToken = /(?s).*rte.*/
"java: ${content.matches(replToken)}, groovy: ${(content =~ replToken).find()}"
java: true, groovy: true

Remember to write a pattern that matches to the whole response.



Showing results for 
Search instead for 
Did you mean: