When using a data source, it is much harder to use an XML Assertor tool statically, because it will check for the same element returned in every example. Instead of searching for a static value, it is helpful to check that the result has the expected value dynamically. In this example, we will ensure the returned title contains the word from the data source.
- Right-click the Test 1: getItemByTitle node from the previous exercise, then choose Add Output.
- 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 here, 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’s Configuration tab, select contain from the Element must drop-down menu, select Parameterized from the Expected Value drop-down menu, and select Keywords from the last drop-down menu.
- Save the changes to the XML Assertor Configuration.
- Click the Test toolbar button.
Note that the test will fail after a couple runs due to the same XPath we ignored earlier (in Excluding Dynamic Values from Diff Comparisons). If you configure the new Diff tool to ignore that same XPath, the tests will succeed.