This topic covers the XML Assertor tool in SOAtest and Virtualize. This tool enforces the correctness of data in an XML message. This tool requires a validate license.
Sections include:

Understanding XML Assertor

This tool is most commonly connected to a SOAP Client or Messaging Client in order to verify the data returned by a service. XML Assertor provides support for complex message validation needs without the need for scripting, and allows you to easily create and maintain validation assertions on your XML messages.

When verifying results from a service, you may want to apply specific rules conformant to your business requirements. It may not be sufficient to verify that changes occurred; you may also want to define complex rules defining what constitutes an acceptable XML message.

XML Assertor is designed to provide a range of assertions which can enforce more logical and business-appropriate rules for message validity.

Configuring XML Assertor

XML Assertor consists of three main tabs:

To configure XML Assertor: 

  1. Click the Add button in the XML Assertor’s Configuration tab.



     The Select Assertion wizard displays.



  2. Select an assertion type. The following is a brief summary of the available types of assertions.
  3. Click the Next button. A tree view displays.



  4. Select the element that you want this assertion to check, then click the Finish button. Note that you can edit the structure of this tree in the XML Assertor tool’s Expected XML tab.

You may add additional assertions to apply to the message (such as a Numeric assertion to enforce on the price element) by clicking the Add button in the Configuration tab.

If you later want to modify the element referenced by an assertion, click Change Element, which is at the bottom right of the Configuration tab. This opens a dialog that lets you graphically or manually edit the given element. You can click the Evaluate XPath button to see the result of applying the XPath expression against the expected XML.

 

 Note that the Trim content option will remove any white space from the start and end of the extracted string before comparing it to the expected text. For example, if "  bar " was extracted (ignore quotes in all examples; they are used to show white spaces), it would become "bar"; this would match "bar" (and fail to match "  bar ") if the Trim content option was not enabled.

If you have XML like the following

<foo>
bar
</foo>

where the new-line characters before and after the "bar" value are uninteresting and mostly a matter of formatting, you might want to enable this option so you don’t have to account for the format of the XML when creating an extraction.

Parameterizing XPaths


You can parameterize XPaths to reference test or Responder suite variables, environment variables, and data source values.  The syntax to reference variables is ${myVariableName}. The syntax to reference XML Data Bank values and Data Source Values is: ${myColumnName}. 

For example, if ${XPath Key} is a data source column name, you could use

/*[local-name(.)="bookstore" and namespace-uri(.)=""]/*[local-name(.)="book" and

namespace-uri(.)=""][child::node()[local-name(.)="title" and text()="${XPath Key}"]]