Assertions in soapUI – Why? How?

Posted: January 28, 2011 in Assertion in soapUI
Tags: , , ,

Before diving deep into the soapUI Assertions topic, let me throw some light on the word “Assertion” itself. This word may not be known to many of entry level testers. So we will go with the dictionary definition of the verb “Assert” which then forms the noun “Assertion”.

Assert: To declare or affirm solemnly and formally as true

Assertion: The act of affirming, asserting or stating something

From the above provided definition, we can conclude that Assertion in soapUI would help testers to affirm/confirm the correctness of test results/response. I assume that this answers the first part of the question “Assertion in soapUI – Why”.

Now moving to the second part of question “Assertion in soapUI – How”, which would require a detailed explanation. soapUI 3.6 supports around 14 different types of assertions, however in this blog we will cover the very basic & frequently used Assertion types. Below I have provided some assertions types and the detailed information about them.

Type Details
Schema Compliance validates the response message against the definition in the WSDL and contained XML Schema
SOAP Response checks that the response is a valid SOAP message, always use this to make sure you are actually getting a response (if no assertions are added a connection error will not cause a failure).
SOAP Fault checks that the response is a SOAP Fault (for negative testing)
Not SOAP Fault checks that the response is not a SOAP Fault. Never use this assertion type together with SOAP Fault, since they will have opposite results always [i.e., compliment of each other]
xPath Match validates the response message against the data returned by xPath expression & any tag in response.
xQuery Match validates the response message against the data returned by xQuery expression & any tag in response.
Contains validates the response message contains a particular string or regular expression provided in ‘Contains’ assert condition.
Script Assertion validates the response message against data returned by the code of lines written in Groovy script. Useful to verify the response data against the Database which can fetched using Groovy script

Assertion can only be used with either Test Step or Test Cases. It is not possible to put an assertion in the request template under the Binding Operation/Method. To put an assertion, click on the icon (refer attached screen shot) next to “Run the Test Step”

Now refer the below attached 2 screen shots for an example of xPath assertion in soapUI. Any xPath assertion would comprise of 2 things – (a) is xPath expression to evaluate the XML file and fetch the required data. (b) the expected response which needs to be compared against the xPath expression result.

I have used the following xPath expression :

declare namespace ns1=’’;

xPath Assertion - Passed

xPath Assertion - Failed

I hope these snapshots & the blog content would be of some help for you to understand the “Assertion in soapUI “ .

EndNote: Assertion are very useful while performing the regression testing and to validate the test results without digging into much details.

  1. Prachi says:

    Helpful Explanation!

  2. Imran says:

    I have a question reagarding how to verify by adding assertion;
    – distance < 2.2

    if this is the condition I dont know how to add an assertion in SoapUI where you can verify this…. I know you can similar condition like this using Contain assertion if
    – distance = 1.8

    In general i am looking for verifying conditions using assertions like or !=
    Your response will be helpful.


    • Imran,

      There is no direct assertion provided in soapUI to perform the logical/conditional operations. However with the next release (soapUI 4.5) this is one of the top feature request & work in progress.
      And to achieve what you are looking for can be done using Groovy script assertion.
      use XmlHolder & GroovyUtils to capture the node value (to be compared)

      assert distance < 2.2 //if distance is a value in userdefined property (string) then you must convert it into Integer. Or an alternative convert both into String

      expectedValue = 2.2
      distanceValue = getNodeValue (….)
      assert distanceValue < expectedValue.toString()

      I hope this will help.

      Best Regards,
      /Pradeep Bishnoi

  3. amit says:

    Hi pradeep ,

    Can u please explain me .
    How to use Contain Assertion for any dynamic value .
    or if there is any other assertion to check the dynamic value

    Its urgent.

    • Hi,

      Have a huge list of interesting blogs in DRAFT mode including this one & will publish them soon (if time permits).
      To make your contains assertion dynamic i can always use the context expansion. Say i have a testCase property value (myProp) which is getting updated from a file using some groovy code.

      Now after adding a contains assertion in my teststep i can set the expected result to match with the content of the property variable (which will change with content of files). Expected result should be like :


      Done! Now my contains assertion is dynamic. Try this & share this 🙂
      {Pradeep Bishnoi}

    • ginny says:

      Hi Pradeep ,
      There is one value which is changed after every execution , now i have to check the value whether is correct or not by using the assertion .

      Which assertion i can prefer and How.
      Please lemme know.

      • Hi,
        For your case, if the node location is always same then ‘xPath’ would be prefered.
        If the node value (after execution) would be unique in response then ‘Contains’ can be used.

        {Pradeep Bishnoi}

  4. amit says:

    Thanks pardeep 🙂
    Helpful Explanation!

    One more Query

    Can u please explain, how this statement works under Xpath assertion with using ‘by content matching RegEx’ .

    matches( //ns:addPropertyResponse[1]/ns:return[1]/ax23:propertyRSN[1]/text(), ‘.\d’ )

    matches( //ns:addPropertyResponse[1]/ns:return[1]/ax23:propertyRSN[1]/text(), —-Getting the response from where
    ‘.\d’ — getting the reponse from where

    • From your syntax i can bet you are using a PRO version 😉
      And soapui does provide good support to PRO customer. With this blog i am trying to help people with soapUI Open Source.

      Anyways, matches is Xpath function to match two values (actual, expected).
      Value 1 – first part of xPath expression : fetches the value from your response using Xpath expression [aka Actual value]
      Value 2 – second part : is the regular expression that defines the condition of our expected result. [aka Expected value]

      Hope this will help.
      {Pradeep Bishnoi}

  5. amit says:

    Thanks pradeep

  6. ginny says:

    Hi Pradeep ,

    I created project with SoapUI Execute it some times, save. All OK.
    when I try to open saved project and tries to execute the webservice then I got message – “Do you want to Recreate a default message from the schema?
    After click on yes / No option all the fields get disappeared from the webservice
    Removing and reimport project doesn’t resolve the problem.
    Removing and recreate the web services doesn’t resolve the problem.

    I tried recreate project some times, the same behavior.
    its Urgent .

    Thanks in Advance .

    • Hi,

      This is strange. Can’t comment on thisone until i see the application WSDL/XSD.

      {Pradeep Bishnoi}

      • bsk says:

        Hi Pradeep,

        I have gone through few of your posts on SOAPUI. All your posts are really amazing…thanks a lot for all your posts.

        We wrote few SOAP UI test cases for the REST Web services but now I have to do the SOAPUI LOAD testing for those REST Web services so could you please guide me the best step by step materiel/document for SOAPUI load testing? Or could you please provide me some basic information about what is soapui load testing and steps to do the load testing?

        Thanks in advance!


      • Hi BSK,

        i hope you have referred this blog :

        {Pradeep Bishnoi}

      • bsk says:

        Hi Pradeep,

        First of all I would like to tank you for your reply.

        Actually I have gone through this( block and I have implemented a simple load test as well but now my issue is as follows:

        I have a Test Case with 4 test steps, these 4 test steps using the Test Case Level properties so when I have created the load test for this test case, I must pass the different different values for each Thread. As per your groovy script we can dynamically change these custom properties by adding a groovy script step in the beginning of the test case but these custom properties must not be change until the the last step execution.

        The threads are parallelly executing so the 2nd thread is changing these custom properties as part of their execution before completing the 1st thread execution so is there a way to specify the dynamic values to each thread execution and these passed values should not change until the all Test Steps of that Thread completed.


  7. Hi

    I am having this response for my soapui

    Description of Group 101

    02/06/2012 12:59:38 PM

    I added the following assertion for finding STATUS in response i.e., OK

    declare namespace soapenv = ‘’
    declare namespace ns = ‘’;
    declare namespace ax21 = ‘’;

    But it throws following error
    XPathContains assertion failed for path [declare namespace soapenv = ‘’
    declare namespace ns = ‘’;
    declare namespace ax21 = ‘’;
    //soapenv:Envelope/soapenv:Body/ns:FindgroupsResponse/ns:return/ax21:status] : Exception:Missing content for xpath [declare namespace soapenv = ‘’
    declare namespace ns = ‘’;
    declare namespace ax21 = ‘’;
    //soapenv:Envelope/soapenv:Body/ns:FindgroupsResponse/ns:return/ax21:status] in Response

    Can u please explain what is wrong in it.


  8. Avasur says:

    Hi All,

    I am new to soapui and stumbled up on your forum when searching for answers to my problem.
    I am trying to give Xquery assertion to validate the specific nodes returned in the response. When I added the following Xquery assertion to the Request or to the Assertion Test Step, I get the message that the assertion ran with OK status(OK:took 0 ms). But when I change a value in the assertion the test case does not fail instead it still finishes with out the assertion test step being failed. It seems the Assertions are being validated against the response message. I am not sure how to correct this. Please help me understand what I am wrong and resolve this please?

    Xquery Expression:

    declare namespace ns1=’’;
    declare namespace i=’’;
    declare namespace a=’’;
    declare namespace s=’’;

    for $x in //DomainValue
    order by $x/Code
    return {data($x/DescriptionEn/string())}

    Expected Result:


  9. Krish says:


    I want to compare my received response to 2 values.
    I am using XPath match assertion.
    However, I can compare it to only one value and in that case one of the two assertions fail.
    Suppose I receive the value of URI tag, I want to verify that the value should be either URI1 or URI2.
    How can I achieve this? Can I use something like OR operator in the expected result field? Or should I use some other assertion?

  10. bhavya says:

    Hi Pradeep Bishnoi -i am new to soap ui ,i want to do automation fro copule of scenairos like i have wsdl with address details and i wil upload that wsdl and get request and response i want to add validation for htose address feilds like if i leave all those address feilds blnk and wrong data means it shud throw error .how do i give contion fo rthis,i tried xpath ..but its not working

  11. bhavya says:

    please provide mesolution sooon ASAP

  12. Marco says:

    Thx helped me a lot 😀

  13. Hey! I was wondering if someone can help me figure out a way to add an encoding exception for French accent through in built settings maybe?

  14. Rahul Vohra says:

    I want to know…How to Get the values in one shot for 40 assertions on 1 step?Otherwise i have to click “Select from the current” on each assertion.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s