Whenever we are testing the APIs of an application, there are requirements that we need to extract the values from the response of one API. And pass those values in the request for another API. To handle such scenarios, we need a mechanism using which we can extract the value of a specified key and pass the same in some other API requests. We learned in the previous article that we can set and extract specific values of keys using "Properties in SoapUI. " Further, SoapUI provides the capabilities to transfer these properties across various TestSteps. In this article, we will cover the following details for understanding the "Property Transfers in SoapUI":
- What is Property Transfer in SoapUI?
- How to add property transfer in SoapUI?
- How to consume a Property Transfer in SoapUI?
What is Property Transfer in SOAPUI?
As we know, Properties in SoapUI act as a central repository to store the needed information and be accessed using a named key. Now, the next question which will be running across your mind would be, what is property transfer?
Let us learn this with the help of following the response of the Bookstore API.
Let's assume we want to use the "ISBN" field value from the above response as part of a test step and transfer it to the other elements of the project, which can be to a property or a different request.
In such a case, we need to have a mechanism to retrieve the value and set it to another element. SoapUI supports such functionality through the Property Transfer TestStep.
Let's understand how we can add a property transfer in a TestStep in SoapUI:
How to add property transfer in SoapUI?
Property Transfer can add as a test step in SoapUI, and SOAP UI provides an intuitive wizard for Property Transfer.
Follow the steps below to add Property Transfer as a test-step:
Step 1 − Select the TestStep, right-click → Insert Step → Property Transfer.
Step 2 − You will see the "Add Step" pop-up, enter a logical name of the test step, and click "OK".
We are using the name of TestStep as "ISBN Transfer" as displayed above.
Step 3 − After the addition of the step, a new wizard will open. You can add multiple properties from headers/ body and use them
Since we want to use "ISBN" from the response of the bookstore API, click on the highlighted "+" button.
Step 4− After clicking "+" as specified in the above step, it will prompt you to enter a name for the value to transfer.
Add a logical name of the transfer and then click OK.
As displayed in the snippet above, the addition of a new Transfer to the list happens.
How to consume a Property Transfer in SoapUI?
As we have added a Property Transfer, let's see how we can consume these values. Once the Property Transfer addition happens, you will see that there are two areas Source and Target marked as steps 1 &2. Let's understand these in detail.
Before this, there are two other values specified to identify a property, namely "Property" and "Path Language", indicated by step A & step B in the snippet above. Let's understand all these sections:
- Source: This area records the source of the property from which the extraction of the value of property happens. It displays all the possible values of the project where we have already defined properties. Few of them are:
In the snapshot, you see Globals, Project, Test Suite1, etc. Selecting the Global will enable selecting the global property that we may have defined. In the snapshot below, We have chosen the Globals as a source.
SOAP UI will auto-populate all the global properties already defined and facilitate the user of selecting any of them as a source. For details on how to set different levels of properties, including the Global property, please read the previous article "Working with Properties in SoapUI".
Likewise, if you select other levels (Project, Test Suite, Test Case, Test Step), SoapUI will display the corresponding already defined properties, so that they can be used to store the values.
- Target: This area facilitates the user from receiving the value extracted from the source. It also contains all the different properties that are available in the source.
As mentioned above, there are two other values specified to identify the property value, namely "Property" and "Path Language", indicated by step A & step B in the snippet above.
- Property: Property parameter displays the property from the selected source.
- Path Language: In case we want to extract a property value from a Request, Response, or Endpoint, basis on the format of the request/response, which can be either a JSON or an XML, we select the Path Language.
For our example where we want to extract the value of ISBN from a JSON response, we are going to set Path Language and see this in detailed steps below.
Step 1: Firstly, select the Source, Response, and Path Language to extract the ISBN.
- Since we want to extract the value from the target response, Select "Response" in the Property dropdown.
- Select JSONPath from the Path Language dropdown because we want to extract ISBN from the response of REST request.
Now, you might be wondering what if you need anything from the Headers? Hold On! SoapUI can help you in that case too. Apart from Headers and API response, you can select various other parameters from Property Dropdown as shown below :
Step 2 − Secondly, to get the declaration of source JSON, specify the JSON path. In our case, let's use $.books.isbn to get the ISBN number from the Book Store API. We will be using this ISBN number to retrieve the record of the specific book related to this ISBN number.
NOTE: The leading $ represents the root object or array and can omit.
Step 3 − Thirdly, specify the target where the value extracted (ISBN) from the above JSON path expression will transfer. We use the target pane at the bottom of the property transfer window for that.
Let's define a new property, as shown below, which we will use to set the value of ISBN extracted in step 2.
Now navigate to the Property Transfer wizard and from the Target select the getISBN property as shown below:
- Target as Properties (indicated by Step 1) shows that we want to set the value as one of the properties.
- Property as the name of the property (indicated in step 2), which we get the value.
Step 4 − Finally, click on the "Run" icon (highlighted as step 1 in the screenshot below). Now once the test case runs successfully, the property "ISBN" gets updated based on the response of the API.
This log shows (highlighted by marker 2) the details of the transfer and its status. In our case, we were successfully able to transfer the property, and the transferred value is as highlighted in the above screenshot.
So, this was we could transfer the values of properties extracted from the Response Header/Body of one REST API to another API or TestCase and implement "Property Transfer in SoapUI". Additionally, we can follow the same steps to implement the Property Transfer in SoapUI for the SOAP project also.
- Property Transfers helps in transferring the values of properties across various TestSteps or TestCases.
- Moreover, we can access the properties of all levels(e.g., Global, TestSuite, etc.) got getting and transferring the values of Properties.
- Additionally, we can quickly transfer the properties in SoapUI using the "Transfers Wizard". We can do it by selecting the Source and Targets of the property.
Consequently, let's now move to the next article, where we will learn about the implementation of "Conditional Statements in SoapUI".