How to use SoapUI Assertions
In the previous post, we looked into how to create test cases and adding basic SoapUI Assertions. In this post, we will go into more detail on the various assertion types available.
We will cover the below SoapUI Assertions.
- Contains with Regex
- Not Contains
- XPath with Wild Cards
We will use the same example as we used in previous post (Convert Temperature Soap Service).
Using Contains is pretty straight forward. Just put the entry you want to verify. You can also use the ‘Ignore case in comparison’ option as well.
Contains With Regular Expression
You can use regular regex patterns by enabling the ‘Use token as Regular Expression’ check box as shown below.
If you want to verify that a particular tag or text should not be present in the response, provide that in the Not Contains Assertion. You can use Ignore case and Regex format as well.
XPath is one of the most commonly used methods of assertion in XML data.
We have to first declare the namespaces. This is done by clicking on the Declare button. After declaring the namespaces, we just have to provide the Xpath to validate. Then click on ‘Select from current’ button to insert the value corresponding to the XPath to the ‘Expected Result’ section. This is also a good way to validate the provided XPath as it throws an error if the XPath is invalid. Press Test to check the assertion and click Save.
The entire flow is given below.
XPath with Wild Cards
We can use wildcards in the Expected Results as shown below.
We can also use XQuery to perform the validations in case of multiple results. Example is shown below.
Similar to XPath, we have to declare the namespaces. We also have to give a root for the response as shown below using <result> tag. Inside that we have a for loop which loops in the provided XPath value. Inside the loop, we return the required data within a tag (<entry> in this case). This way, even though the actual response contains different data, we just have to provide the tags we need to validate in the Expected Result section.
We will be covering Using Groovy in SoapUI in a future post.