SOAP UI – Working with assertions
Assertions are used to validate that the request executed is successful and the response received as a result of execution matches the expected result/value.
** Update –
In this tutorial let’s see,
- How to create many assertions for your request in TestSuite?
- How to manage assertions in your request?
Complete SoapUi Tutorials now available here
ADD more assertions to your request:
Follow the steps below to add assertions to your request available in a testsuite.
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:
- Property content: Used to validate the properties in a response received after triggering a request for a particular service.
- Contains: Searches for the existence of a string in the property value/ tags in response xml.
- Not contains: Searches for the non- existence of a string in the property value/ tags in response xml.
- XPath Match: Match the content available in the property value/ tags in response xml with the expected value.
- XQuery Match: Compare content selected from target property with the expected value.
- Compliance, status and Standards: Checks for the schema compliances, status of the fault messages received in the responses.
- Invalid HTTP Status Codes: Checks that the target HTTP result code with the status code that is not defined in the list of defined codes.
- Not SOAP Fault: Validates that the last received message is not a SOAP fault.
- SOAP Fault: Validates that the last received message is a SOAP fault.
- Schema Compliance: Validates the response received is in compliance with the WSDL schema definition
- Script Assertion: Runs a script to perform arbitrary validations.
- SLA :
- Response SLA: Verifies the response time with the specified or defined limit.
- JMS Status: Validates the JMS request of the target test step is executed successfully.
- JMS timeout: Checks the target test step did not take longer time duration than the defined time limit.
- Sensitive Information Exposure: Checks the response received doesnât expose any sensitive information about the target system.
- Contains – checks for the existence of a specified string
- Not Contains – checks for the non-existence of a specified string
- Reponse SLA – check the response time against a specified value
- XPath Match – compares the result of an XPath expression to an expected value
- XQuery match – compares the result on an XQuery expression to an expected value
- Script – runs an arbitrary script that can be used to validate the received message as desired
Let’s see 2 of the above assertions that can be added to the request in this tutorial.
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: