Applies to ReadyAPI 2.8, last modified on August 16, 2019

The XPath Match assertion allows you to use an XPath expression to select content from the target request or response node and compare it with the value you expect.

Important notes:

  • This assertion applies only to requests and responses with XML data in the body.

  • ReadyAPI cannot parse XML documents that contain the byte order mark (BOM) character.

Availability

This assertion is available in multiple ReadyAPI applications. Depending on the application, it validates the following data:

In... Checks... To learn more...
SoapUIĀ functional tests The request or response body. See Working With Assertions in SoapUI.
SoapUIĀ security tests The response body. See Security Assertions.
ServiceV The request body. See Assertions in ServiceV.

Create an assertion

Follow these steps:

SoapUI: The Assertions panel

Click the image to enlarge it.

  1. Open a test step.

  2. Click Add assertion.

In the New Assertions dialog, search for the XPath Match assertion or select it manually in the Property Content category.

Follow these steps:

Secure: The Assertions panel

Click the image to enlarge it.

  1. Open a security test.

  2. Select Response Assertion.

  3. Click in the Assertions panel

In the New Assertions dialog, search for the XPath Match assertion or select it manually in the Property Content category.

Follow these steps:

ServiceV: The Assertions panel

Click the image to enlarge it.

  1. Open a virtual service.

  2. Open the Assertions drop-down panel.

  3. Click in the Assertions panel

In the New Assertions dialog, search for the XPath Match assertion or select it manually in the Property Content category.

Setting up properties

  1. In the XPath Expression edit box, specify the XPath expression you want to use for this search or use the toolbar controls.

    To use the toolbar controls, run the request you want to validate at least once.

    ReadyAPI: Configuring the XPath Match assertion

    Click the image to enlarge it.

    To create the expression automatically, click one of the following icons on the toolbar:

    Option Description
    Select node Call the Select XPath dialog. Use it to select a node from the last request or response and create an XPath expression for this node. See below.
    Namespace Get the last request or response namespace and declare it.
  2. 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.

    Use these commands to select the value from the existing request or response:

    Option Description
    Select Content Add a property expansion to the result.
    Select from Current Get a value from the last response you have received (or the last request the ServiceV virtual service has received).
  3. If needed, use additional options to enhance the results you will get:

    Option Description
    Allow Wildcards 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.

    Show Example

    Ignore XML comments Skip XML comments during the comparison.
  4. To test your assertion on the last response you have received (or the last request the ServiceV virtual service has received), click Test.

Tips

To avoid typing the desired XPath expression manually, click Select XPath and select the desired XML element or attribute in the subsequent dialog.

ReadyAPI: Selecting an element for XPath expression

ReadyAPI will form an XPath expression that points to the selected item, and will set the result of the last request or response as the expected result.

If a node you are selecting contains a single child, ReadyAPI will try to get its text instead of the object itself.

Show Example

  • The following expression gets the value of the type attribute of the password element in the login request:

    //sam:login[1]/password[1]/@type
  • The following expression gets the string containing the session ID from the loginResponse response. It uses the concat() XPath function:

    //sam:loginResponse[1]/concat('The user session ID is ',sessionid[1])
  • The following expression gets the value of the description subelement of the item element (with the id attribute equal to 1) in the Response response.

    //sam:Response[1]/item[@id="1"]/description[1]

Add more assertions that validate XML content:

See Also

Property Content Assertions
XQuery Match Assertion

Highlight search results