You can use the XML Assertor tool to enforce the correctness of data in an XML message. It is most commonly connected to a SOAP Client or Messaging Client in order to verify the data returned by a service. The 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.
To use the XML Assertor, complete the following:
- Right-click the Test 1: getItemByTitle node from the previous exercise and select Add Output from the shortcut menu.
- In the Add Output wizard, select Response> SOAP Envelope on the left, select XML Assertor on the right, and click Finish.
- In the XML Assertor panel that opens, open the Configuration tab and click Add.
- In the Select Assertion wizard, expand Value Assertions, select String Comparison Assertion, then click Next.
The String Comparison Assertion dialog displays a tree view of the XML message from which you can select a single value to enforce.
- Select the name element from the String Comparison Assertion dialog and click Finish.
The Configuration tab of the XML Assertor is now populated with a String Comparison Assertion.
- In the XML Assertor panel, choose the Configuration tab
- In the String Comparison Assertion Configuration section, choose contain from the Element must drop-down menu and enter
Linuxin the Expected Value field.
- Save the changes to the XML Assertor Configuration.
- Click the Test toolbar button. The test succeeds.
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 XML Assertor’s Configuration tab.