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.

{"books": [
      {
      "isbn": "9781449325862",
      "title": "Git Pocket Guide",
      "subTitle": "A Working Introduction",
      "author": "Richard E. Silverman",
      "published": "2013-08-02T00:00:00",
      "publisher": "O'Reilly Media",
      "pages": 234,
      "description": "This pocket guide is the perfect on-the-job companion to Git, the distributed version control system. It provides a compact, readable introduction to Git for new users, as well as a reference to common commands and procedures for those of you with Git experience.",
      "website": "https://chimera.labs.oreilly.com/books/1230000000561/index.html"
   },
      {
      "isbn": "9781449331818",
      "title": "Learning JavaScript Design Patterns",
      "subTitle": "A JavaScript and jQuery Developer's Guide",
      "author": "Addy Osmani",
      "published": "2012-07-01T00:00:00",
      "publisher": "O'Reilly Media",
      "pages": 254,
      "description": "With Learning JavaScript Design Patterns, you'll learn how to write beautiful, structured, and maintainable JavaScript by applying classical and modern design patterns to the language. If you want to keep your code efficient, more manageable, and up-to-date with the latest best practices, this book is for you.",
      "website": "https://www.addyosmani.com/resources/essentialjsdesignpatterns/book/"
   },
      {
      "isbn": "9781449337711",
      "title": "Designing Evolvable Web APIs with ASP.NET",
      "subTitle": "Harnessing the Power of the Web",
      "author": "Glenn Block et al.",
      "published": "2014-04-07T00:00:00",
      "publisher": "O'Reilly Media",
      "pages": 538,
      "description": "Design and build Web APIs for a broad range of clients—including browsers and mobile devices—that can adapt to change over time. This practical, hands-on guide takes you through the theory and tools you need to build evolvable HTTP services with Microsoft’s ASP.NET Web API framework. In the process, you’ll learn how design and implement a real-world Web API.",
      "website": "https://chimera.labs.oreilly.com/books/1234000001708/index.html"
   },
      {
      "isbn": "9781449365035",
      "title": "Speaking JavaScript",
      "subTitle": "An In-Depth Guide for Programmers",
      "author": "Axel Rauschmayer",
      "published": "2014-02-01T00:00:00",
      "publisher": "O'Reilly Media",
      "pages": 460,
      "description": "Like it or not, JavaScript is everywhere these days-from browser to server to mobile-and now you, too, need to learn the language or dive deeper than you have. This concise book guides you into and through JavaScript, written by a veteran programmer who once found himself in the same position.",
      "website": "https://speakingjs.com/"
   },
      {
      "isbn": "9781491904244",
      "title": "You Don't Know JS",
      "subTitle": "ES6 & Beyond",
      "author": "Kyle Simpson",
      "published": "2015-12-27T00:00:00",
      "publisher": "O'Reilly Media",
      "pages": 278,
      "description": "No matter how much experience you have with JavaScript, odds are you don’t fully understand the language. As part of the \"You Don’t Know JS\" series, this compact guide focuses on new features available in ECMAScript 6 (ES6), the latest version of the standard upon which JavaScript is built.",
      "website": "https://github.com/getify/You-Dont-Know-JS/tree/master/es6%20&%20beyond"
   },
      {
      "isbn": "9781491950296",
      "title": "Programming JavaScript Applications",
      "subTitle": "Robust Web Architecture with Node, HTML5, and Modern JS Libraries",
      "author": "Eric Elliott",
      "published": "2014-07-01T00:00:00",
      "publisher": "O'Reilly Media",
      "pages": 254,
      "description": "Take advantage of JavaScript's power to build robust web-scale or enterprise applications that are easy to extend and maintain. By applying the design patterns outlined in this practical book, experienced JavaScript developers will learn how to write flexible and resilient code that's easier-yes, easier-to work with as your code base grows.",
      "website": "https://chimera.labs.oreilly.com/books/1234000000262/index.html"
   },
      {
      "isbn": "9781593275846",
      "title": "Eloquent JavaScript, Second Edition",
      "subTitle": "A Modern Introduction to Programming",
      "author": "Marijn Haverbeke",
      "published": "2014-12-14T00:00:00",
      "publisher": "No Starch Press",
      "pages": 472,
      "description": "JavaScript lies at the heart of almost every modern web application, from social apps to the newest browser-based games. Though simple for beginners to pick up and play with, JavaScript is a flexible, complex language that you can use to build full-scale applications.",
      "website": "https://eloquentjavascript.net/"
   },
      {
      "isbn": "9781593277574",
      "title": "Understanding ECMAScript 6",
      "subTitle": "The Definitive Guide for JavaScript Developers",
      "author": "Nicholas C. Zakas",
      "published": "2016-09-03T00:00:00",
      "publisher": "No Starch Press",
      "pages": 352,
      "description": "ECMAScript 6 represents the biggest update to the core of JavaScript in the history of the language. In Understanding ECMAScript 6, expert developer Nicholas C. Zakas provides a complete guide to the object types, syntax, and other exciting changes that ECMAScript 6 brings to JavaScript.",
      "website": "https://leanpub.com/understandinges6/read"
   }
]}

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.

Adding property Transfer in SoapUI

Step 2 − You will see the "Add Step" pop-up, enter a logical name of the test step, and click "OK".

Add name for Step Property transfer in SoapUI

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

further.

SoapUI Property Transfer Wizard

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.

Value Transfer in SoapUI

Add a logical name of the transfer and then click OK.

Property Transfer In SoapUI

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.

Transfer Wizard SoapUI

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:

  1. 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:

SoapUI: Property Transfer Sources

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.

SoapUI - Property Transfer Wizard Global 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.

  1. 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.

  1. Since we want to extract the value from the target response, Select "Response" in the Property dropdown.
  2. 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 :

Property Dropdown

Step 2 − Secondly, to get the declaration of source JSON, specify the JSON path. In our case, let's use $.books[0].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.

Setting Up Property in SoapUI

Now navigate to the Property Transfer wizard and from the Target select the getISBN property as shown below:

Setting Target Value in Property Transfer Wizard of SoapUI

Where,

  • 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.

Run Transfer Wizard In SoapUI

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.

Key Takeaways:

  • 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".

Properties in SOAPUI
Properties in SOAPUI
Previous Article

Similar Articles

Feedback