Learn Assertion in SOAtest with an XML Code Example:
The Key Differences between SOAP Vs Rest were explained in detail in our previous tutorial.
This simple tutorial will explain assertion with a sample XML request/response body in which we will be applying assertions through the XML assertor.
Read through the Entire SOAtest Tutorial Series for in-depth knowledge of the SOAtest.
What You Will Learn:
XML Request and Response
Let’s say that you have the following XML program which you have passed as a payload.
<?xml version="1.0" encoding="UTF-8"?> <!-- This is a comment --> <Envelope> <Body> <getItemByTitleResponse> <book> <id> 01 </id> <name> softwaretestinghelp </name> <price> 100 </price> </book> </getItemByTitleResponse> </Body> </Envelope>
When you execute the test successfully, you will find the response body (same as above) in your traffic viewer.
The real validation starts now. You have to make sure that the response you got is the same as the request that you have sent to the service. One way to do it is by manual validation which means observing the entire result line by line and verifying the value returned for every field.
This won’t make sense while dealing with a huge number of field values in your payload. Hence, we need to add an assertion for the above program.
Now, we are going to assert the value of the name field whose value is “softwaretestinghelp”.
Steps to Follow to Add an Assertion
Enlisted below are the various steps that have to be followed in a chronological order to add an assertion.
#1) Choice of Assertion
Before we proceed further, we will create a column in our data source (Excel), say the “keywords” column which stores all the possible values to be returned.
Now, we have to identify the type of assertion which we are going to add to the suite. As the name field is of type String and it will always return a string value like “softwaretestinghelp”, we are proceeding with the String Comparison Assertor (which is a part of Value Assertion).
#2) Add XML Assertor
Now, you have to click on the test which you just executed to get the response.
After selecting the test, follow the below steps:
- Right-click on your test => Add Output => Response => SOAP Envelope => Select XML Assertor.
- Click on Finish.
#3) Configure XML Assertor
As you have added XML Assertor, double-click on it and then click on Add button.
#4) Select XML Assertion type
Once, you clicked on the Add Button from the above screenshot, you will find all types of assertions that are available in the XML assertor.
Out of these five assertions, click on Value Assertions (expand it) => select String Comparison Assertor => Click Next
Once, you have clicked the next button, you will find your response body in the following format.
Select the field whose value has to be asserted. In our case, we are going to select the name field => Click Finish
#5) Apply Assertion
After you have clicked on the finish button, go to the XML assertor’s configuration tab => Select contain from the element must drop-down menu => Change the expected value from fixed to parameterized => Select Keywords from the drop-down menu.
Now, save all the open tabs before closing it and execute again.
Please note that “Keywords” is the column of your data source which has all the possible names (in our case softwaretestinghelp) already defined. When we are using a data source (Excel), it is much harder to use an XML Assertor tool statically, as it will check for the same element returned in every test executed.
Instead of searching for a static value, it is helpful to check if the result has the expected value dynamically.
PREV Tutorial | FIRST Tutorial