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. |
Availability
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. |
Create an assertion
Setting up properties
-
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:
Option Description Allow Wildcards Command the assertion to use an asterisk wildcard ( *
) for varying parts of the value.
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.
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.
Examples
-
The following XQuery expression sorts the
price
subelements of theResult
element in the ascending order:for $z in //item
order by $z/id
return <price>(data($z/price/text())}</price> -
The following XQuery expression lists all users from the marketing department:
//user[contains(LINE, "marketing")] -
The following XQuery expression lists IDs and last names of all users:
for $b in //user
return <user> { $b/id } { $b/name/last } </user>
Other assertions for XML data
Add more assertions that validate the XML content: