XPath assertion uses XPath expression to select the target node and its values. It compares the result of an XPath expression to an expected value. XPath is an XML query language for selecting nodes from an XML.
Step 1 − After clicking Add Assertion, select Assertion Category – Property Content.
Step 2 − Then, select Assertion Type – XPath Match and click Add.
XPath Match Configuration wizard opens. Before adding a XPath, declaration of the NameSpace is required. An XML namespace is a collection of names, identified by a Uniform Resource Identifier (URI) reference, used in XML documents as element and attribute names. The same is used in SoapUI XPath Assertion.
Step 3 − For declaring XML Namespace, click the 'Declare' button, which would do the job, else manually declare a namespace.
Step 4 − After declaring the namespace, refer the XPath using the created namespace.
Upon clicking the 'Declare' button, two namespaces will pop up with two URIs. One of them is the schema URL and the other corresponds to the actual web service URL. We need to use the actual namespace where the web service is located and NOT the schema namespace while referencing XPath.
Step 5 − Enter the XPath of the XML node that needs to be validated. //ns1:ConversionRateResult gives the value of the node enclosed between <ConversionRateResult> & </ConversionRateResult> and ns1 corresponds to the declared namespace pointing to 'www.webserviceX.NET'
Step 6 − After entering the XPath, click the 'Select from current' so that the value from the current response would be picked up for comparison going forward. The value can be edited by the user.
Step 7 − Click Save.
The added assertion will be displayed as shown in the following screenshot.