2

There's one tag in my XML response whose elements (JSON Data) always come in different order. Is there any way to create a contains assertion with AND/OR operations or should I just use a Script Assertion? How could I accomplish this verification with XPath?

Edit: I'm using the Community Edition

  • The order in which elements appear hardly ever matters with XPath. So if you can use XPath, show what variants of input you have and we can help you with constructing the correct expression. – Abel Oct 16 '15 at 22:00
  • you using Pro or Community edition? If Pro, there is a feature that does this (as per answer below), if Community its easily done with a groovy script. If you provide an example, I can provide a code sample to get you started – ECiurleo Oct 20 '15 at 10:36
1

So basically I found out the way to do it through a Groovy Script. I used the JsonSlurper util as with Groovy is really flexible and allows me to manage the XML Response as a Key-Value data structure. An example of my solution is shown below:

import groovy.json.JsonSlurper
def xPath = '//ADDITIONAL_INFORMATION'
def addinfo = context.expand( '${verifyTransaction#ResponseAsXml#'+xPath+'}' )
def object = new JsonSlurper().parseText(addinfo);

assert object instanceof Map;

assert object.key_1 == 'Information1'
assert object.key_2 == 'Information2'

...

Hope this helps somebody with the same question.

  • Good to hear, that you got solution for your issue. – Dhiman Oct 20 '15 at 14:08
0

Yes, you can achieve this kind of configuration using the Grouping Assertions method. You can create mutliple contains assertions and group them to form a grouping assertion.

Once assertions have been created (two or more), they can be grouped as shown below. Grouped assertions can use either an AND or OR logic for more sophisticated assertion management.

AND: All assertions evaluated to VALID will assert a PASSED group condition

OR: At least one assertion within the group must evaluate to VALID to assert a group PASSED condition.

The only thing/limitation is, this feature may only be available with PRO version of SoapUI (but first you should check on your version too). Hope this helps you.

  • Alternative could be a groovy script where you do the assertions by yourself? (Didn't use SoapUI for a long time, so I might be outdated) – bish Oct 19 '15 at 16:26
  • This is a good answer, however I just used a JSON Parser in a Groovy Script – Venom Oct 20 '15 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.