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.

SoapUI Assertions

We will cover the below SoapUI Assertions.

  • Contains
    • Contains with Regex
  • Not Contains
  • XPath
    • XPath with Wild Cards
  • XQuery

We will use the same example as we used in previous post (Convert Temperature Soap Service).

SoapUI Assertions Request and Response



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.

SoapUI Assertion Contains

Contains With Regular Expression

You can use regular regex patterns by enabling the ‘Use token as Regular Expression’ check box as shown below.

Contains Regex

Not Contains

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.

Not Contains

XPath Assertion

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.

SEE ALSO:   Upload Files using Selenium WebDriver

The entire flow is given below.

XPath Assertion


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.

XQuery Assertions

We will be covering Using Groovy in SoapUI in a future post.

Further Reading:

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *