HomeSOAPUI

How to add web services Assertions in SoapUI

How to add web services Assertions in SoapUI
Like Tweet Pin it Share Share Email

In the article web services testing in SoapUI you have seen how to create a SOAP project add WSDL and give input to a request and submit to get the response of the SOA Web service. In this article you will know how to add request to a test suite, executing a test case and then add Assertions to verify the responses.

Step by step instructions to add a request as a test case to a test suite.

  • Once you are on the Request Editor Window, i.e. post creating SOAP project and entering test data for a method.
  • Click on Icon to Add as TCIcon to add the current request to a test case.
Add As Test Case
Add As Test Case

  • You would be popped up with a small dialog window to enter a test suite name.
  • Enter desired name( ex: WeatherReport ) and click on OK button.
TestSuite Name Window
TestSuite Name Window
  • Enter desired test case name ( ex: GetCities )  that you want to give for this request in the test suite and click OK button.
TestCase Name Window
TestCase Name Window
  • You will be presented with a window with several check boxes as what all validations you want to include by default when adding this request as a test case in the test suite. Leave the defaults and click OK button for now.
Add Request to Test Case Window
Add Request to Test Case Window
  • The test suite gets created with name WeatherReport (present in the left side of the below image) and you will also see “GetCities” window, where “GetCities” is your test case name.
TestSuite Created
TestSuite Created
  • Click on Submit Icon Execute or Submit Icon to execute the test case, which has only one test step i.e. to getCitiesByCountry.
  • In the test case log, double click on Step 1 to open the Message Viewer window, in this window you can see the three tabs:
    1. Request Message – Shows you the submitted request payload
    2. Response Message – Shows the response XML for this execution request.
    3. Properties – Shows you the list of properties of this request like the Time Taken to execute, Encoding, Endpoint url, and time stamp when the request got executed. It also has other properties which are not relevant for the current article.
    4. Close the Message Viewer window to continue the usage of the tool.
Message Viewer
Message Viewer
  • If you want to add more test steps in a test case, you can right click on test case in the left side tree and select “Add Step” you will be presented with a context menu having lot of types of test steps that you want add. We shall have another article to discuss in detail about each type of test step.
Add Test Step
Add Test Step

Now that you are aware of adding request as a test case in  a test suite.

Lets look at step by step instructions to add Assertions and submit the web services request.

  • Close the GetCities Window in continuation to above steps.
  • On the left side, double click the request present at WeatherReport>GetCities>Test Steps(1)>GetCitiesByCountry – Request 1, you would now be presented with GetCitiesByCountry – Request 1 Editor
Request in Test Suite
Request in Test Suite
  • At the bottom you can see a green icon as Assertions (1) , click on it, you can see the list of assertions available for this request.

    View Assertions
    View Assertions
  • Click on Add Assertion Icon to see the “Add Assertion” Window, in this window you can see the list of assertions that you can add to this request / test case.
  • We shall write another article to give detailed description for each of the Assertions and type of assertions, in this article lets see how you can add a “Contains” assertion, which checks if the returned response contains a text which you are expecting to have.

    Add Contains Assertion to Request
    Add Contains Assertion to Request
  • Select “Contains” under “Property Content” Assertion type and click “Add” button.
  • In the Contains Assertion window, give your text which you want to verify if it is present in the response returned.

    Contains Assertions
    Contains Assertions
  • You can use options like Ignore case or use token as regular expression based on your need.
  • Click on OK button to add assertion to the request / test case.
  • The moment assertion is added, SoapUI intelligently validates if the latest response and results with pass or fail. In this instance the assertion failed when we added “California” as the Contains Assertion text as shown below:

    Assertion Failed
    Assertion Failed
  • We would suggest you to play around these assertions and see the results accordingly, as a practise try to add a Contains Assertion with text “Midway”, you should be getting a pass result for this example.

Now that you have learnt how to add Assertions in a test case, please give some trials till we come up with a next article around SoapUI.

In case of queries, please ask us through comments, we would be more than happy to help you.

 

Comments (0)

Leave a Reply

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