The XQuery Match assertion uses an XQuery expression to select content from the target property and compare the result with the value you expect.
This assertion works like the XPath Match assertion, except that it uses an XQuery expression to select the XML node to be checked instead of XPath. This leads to the following advantages:
You can select and merge nodes you need into one XML result.
You can put results in any order, creating assertions independent of the XML message item order.
|This assertion applies only to requests and responses, bodies of which contain XML data.|
This assertion is available in multiple ReadyAPI applications. Depending on the application, it validates the following data:
|In...||Checks...||To learn more...|
|Functional tests||The request or response body.||See Working With Assertions in Functional Tests.|
|Security tests||The response body.||See Security Assertions.|
|Virtual services||The request body.||See Assertions in Virtual Services.|
In the XQuery Expression edit box, specify the XPath expression you want to use for this search, or use the toolbar controls to create the expression automatically.
|To use the toolbar controls, run the request you are planning to use for the assertion at least once.|
Click to get the last request or response namespace and declare it.
In the Expected Result edit box, specify the value you are expecting to get. You can use the property expansion to point at a specific node.
To get a value from the last response you have received (or the last request the virtual service has received), click Select From Current.
If needed, use additional options to enhance the results you will get:
Command the assertion to use an asterisk wildcard (
Note: If you do not select this option, the assertion will fail on dynamic values.
|Ignore Namespace Prefixes||
To avoid name conflicts, XML elements use prefixes. A prefix points to a namespace that is associated with an element. Typically, the namespaces are represented by URIs. When this option is disabled, the assertion compares both prefixes and corresponding URIs. If this option is enabled, the assertion compares actual URIs that are declared for each prefix, but ignores the prefix names.
Consider two XML elements:
If the Ignore Namespace Prefixes option is disabled, the assertion treats these elements as different; and if the option is enabled, the assertion treats them as equal.
|Ignore XML comments||Skips XML comments during the comparison.|
To test your assertion on the last response you have received (or the last request the virtual service has received), click Test.
The following XQuery expression sorts the
price subelements of the
Result element in the ascending order:
The following XQuery expression lists all users from the marketing department:
The following XQuery expression lists IDs and last names of all users:
Add more assertions that validate the XML content: