2
votes

Using community soapui 5.2.1. Can I use an XPATH assertion to test a number is between two values? This question shows how to do one logical test. But I'd like to store the value in a variable and test on an AND condition. Something like (psuedo code):

declare namespace ns1='http://my.space/XML/output/6.1';

testme=//ns1:items-section[1]/ns1:results/@total_items;

testme > 100 && testme < 200;

If this can't be done, options i see are:

  • retrieving the attribute twice (guess that's not performant)
  • reverting to script assertion (more complex )
  • buy NG PRO ( more expensive)
1

1 Answers

3
votes

IMO generally if you want to apply a pseudo code for assertion purpose I prefer to use script assertion since in SOAPUI Groovy script assertion gives you a lot of flexibility.

However your case seems short, and you're only worried about to avoid perform twice the same XPath; then you can use a option which is not in your list: XQuery Match assertion. The XQuery expression could be:

declare namespace ns1='http://my.space/XML/output/6.1';
declare variable $testme := //ns1:items-section[1]/ns1:results/@total_items;
($testme > 100 and $testme < 200)

Note the use of and instead of &&.

Also you can simplify your XPath expression using * for namespaces:

declare variable $testme := //*:items-section[1]/*:results/@total_items;
($testme > 100 and $testme < 200)

This will return in the expected result:

<xml-fragment>true</xml-fragment> or <xml-fragment>false</xml-fragment> depends on the $testme value.

Hope this helps,