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.
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.
This tool is commonly added from the Create/Update Regression Control dialog for XML messages (by choosing the Create Value Assertion option). For details on adding XML Assertors in this manner, see Validating the Value of an Individual Response Element.
It can also be added via the Add Output wizard, which is described in Adding Test Outputs.
XML Assertor consists of three main tabs:
To configure XML Assertor:
Select the element that you want this assertion to check and click Finish. Note that you can edit the structure of this tree in the XML Assertor tool’s Expected XML tab.
By default, XPath fields are case sensitive, but you can change case sensitivity by specifying the applicable system property when starting Virtualize. See Case Sensitivity for details.
You may add additional assertions to apply to the message (such as a Numeric assertion to enforce on the price element) by clicking Add 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 Evaluate XPath 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.
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}"]]
Video TutorialIn this video, you'll learn how to add targeted assertions for values in XML responses. |
The following tutorial lessons demonstrate how to use this tool: