Index Page

Wednesday, 8 April 2020

How to do Assertions in the SOAPUI tool?

How to do Assertions in the SOAPUI tool?


In test automation, the assertion is the validation step that determines whether the automated test case succeeded or not. If the assertion step fails, then in the Test Report we will get all the assertion failures.


Note - 
a. Below mentioned assertions we can user in both restful APIs or in Web Services APIs.
b. Following assertion can be performed in POST, GET, EDIT and DELETE methods as per assertion needs.

1. Verify HTTP Status Codes: 

To verify API is giving the expected response code or not.

Open Test  Step > Click on assertion plus icon as per below image > Compliance, Status, and Standards > Valid HTTP Status Codes.




 Enter the expected Response Code.



2. Invalid HTTP Status Codes:

Suppose we want to test a negative API scenario then we can use this exception by entering invalid status code.


  Enter the invalid Response Code.




3. Contains:

Verify Response is returning True. Any value which we want to verify in the response we can enter inside the Contains.

Use Path same as above mentioned steps, just click on the highlighted value i.e. Contains.





4. Not Contains:

Verify Response not having null or False Value.
If we want to check response not contains false then we can use Not Contains assertion. Any other value which we do not want in our response can we enter in this assertion.






5. SOAP Response:

If we want to verify, Response is a valid SOAP response or not then we will use 'SOAP Response' assertion. It will scan and say whether it is a valid SOAP response or not.






6. Response SLA:

This assertion is very useful, we use this assertion to check how much time API is taking to execute. 
If we are running our API and it is taking 30 secs to 45 seconds to give the response then there is some problem with API. The results should be instant within 1 to 2 secs.




In below screen API is taking too much time to execute and we have set expected time of API response 1000 ms [i.e. 1 sec] that's why the assertion is getting failed.
1000 ms = 1 second



7. Sensitive Information Exposure:

This assertion we use to check our sensitive information is not getting disclosed. 

If we have used this assertion and sensitive data is used in assertion we will get assertion failure.




As per the below screen, 'employeeAccountNumber' is not fetched in the response that's why an assertion is getting Passed.



All the above 7 steps we have executed in the POST API method, in the following screen we have executed all assertions in GET method as I already mentioned at the starting in the note POSTGETEDIT and DELETE methods can use assertions as per testing needs.





In the next blogs, we will learn, how to do the XPath assertion.

Interview Question from this Page:

a. What is the use of the following assertions, please explain?

1. Verify HTTP Status Codes
2. Invalid HTTP Status Codes
3. Contains
4. Not Contains
5. SOAP Response
6. Response SLA
7. Sensitive Information Exposure


No comments:

Post a Comment