Soap UI Assertions

In this post I am going to explain what assertion in soapui is and how we can apply script assertion.

Assertion

Assertion functionality in SoapUI is used to validate the response of request received by the Test Steps at the time of execution. Usually assertion is to compare a part of message (or the entire message) to some expected value.
Assertion applied in SoapUI at response of request, if any assertion failed then test marked as failed. Failed test can be verify and find out the reason.


Assertion types in SoapUI

1.    Contains
2.    Not Contains
3.    XPath Match
4.    Xquery Match
5.    Scripts
6.    SLA
7.    JMS
8.    JDBC
9.    Security

Script Assertion
In SoapUI Groovy script is used for scripts assertion. Click on assertion option from your created test step.

Click on + icon, select scripts option from popup window and click Add button. Enter assertion name and click on OK button.
Suppose you are getting response in xml format as my test step response is in xml format.


 <responce>
    <status>OK</status>
    <data>2</data>
 </responce>

For above response I used below groovy scrip assertion for status node value


 import com.eviware.soapui.support.XmlHolder
 def holder = new XmlHolder( messageExchange.responseContentAsXml )

 assert holder["//status"] == "OK"
 assert holder["//data"] == "2"


Continue Reading Next => script assertion in Soap UI for WSDL API methods

3 comments:

  1. This is very nice and helpful post for xml response data verification, can you help me to verify json data response.

    ReplyDelete
  2. How can we check path of Data Element using Script
    For example:
    I want to check CountryOfLoss " in following path in response

    RecordClaimDetailsRequest/ClaimDetails/CountryOfLoss

    ReplyDelete
  3. Did you tried

    assert holder["//RecordClaimDetailsRequest/ClaimDetails/CountryOfLoss"] == "Pass here values"

    You need to pass values in double quotes what you want to verify

    ReplyDelete

Leave your comments, queries, suggestion I will try to provide solution