SOAPUI Assertions compare the parts/all of the response message to the expected outcome. We can add a variety of assertions provided by SoapUI to any test step. Each type of assertion targets specific validations on the response such as matching text, comparing XPATH or we could also write queries based on our need. When the test steps get executed, then the associated assertions receive the response for the respective test steps. If any response is failed then the respective assertion will be processed and the corresponding test step will be marked as failed. This notification can be viewed in the test case view. Also we can find failed test steps in the test execution log. The following types of assertions.
• Simple contains
• Schema compliance
• Simple not contains
• Soap Faults
• Response SLA
• XPath Match
• XQuery Match
• WS security status
• Script Assertion
• WS- Addressing Request or Response Assertion
Additionally Equals assertion is introduced in SoapUI NG Pro version.
How to Create an Assertion?
• Create a project, add WSDL
• Add Test suite, Test case and Test steps
• Run the request
To add assertions:
Click on the Add Assertions at the top of log tabs.
Configure the assertions as per the type and data required.
Assertion are very useful while performing the regression testing and to validate the test results without digging into much 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|
Step 1: Click on Request name to open the request editor as shown below.
Step 2: Click on Assertions () tab at the bottom of the request editor as shown in the above image to add assertions.
Step 3: Click on icon to add an assertion to your request. Add Assertion window appears.
Types of Assertions:
The above 2 assertions that can be added to the request
Assertion – SCHEMA COMPLIANCE:
Step 4: Click on Compliance, status and standards assertion tab and choose Schema compliance assertion from the list as shown below and click Add.
Step 5: Configure Schema Compliance Assertion window appears prompting to specify definition url to validate the response.
Step 6: Click on OK to add the assertion to the request.
Step 4: Click on Property content assertion tab and choose Contains assertion from the list as shown below and click Add.
Step 5: Contains Assertion window appears prompting to specify the content to be validated in the response and click OK.
Thus assertion is added successfully to the request as shown in the image below.
MANAGE AND VALIDATE ASSERTIONS FROM TESTSUITE LEVEL:
Click on RUN button as shown in the image below to run the test cases and validate the responses received using the assertions added. The assertion results can be verified using the testcase log as shown below.
Schema Assertion- FAILED:
How to remove assertions from a request:
Step 1: To remove assertions, double click on request name and click on Assertions tab.
Step 2: Select the assertion and click on icon to remove the assertion.
Step 3: Click yes in remove assertion window to confirm removal of the assertion.
Thus assertion is removed successfully.
Run TestCase to validate the contain assertion: