How to Use Properties in SoapUI Groovy Script – SoapUI Tutorial #7

Properties are the central repository to store our information temporarily. These can contain login information like username and password, session data like session id, page context, header information and so on.

This is the 7th tutorial in our SoapUI free online training series.

Let’s see how to add property test step and then we will discuss assigning values to the property and show them in the log.

How to Add Properties in SoapUI:

Here are the steps.

We can transfer the property data across the test steps during the test execution. For that, SoapUI Pro provides Property Transfer test step. Look at the below screenshot.

In the groovy script, add the following script. This script will assign a string text to the property and then it will show in the log after executing the test case.

String testString = "TestString"
testRunner.testCase.setPropertyValue( "Pro_Response", testString )
def getLocalPropValue = testRunner.testCase.getPropertyValue("Pro_Response")

Accessing property:

There are several ways to access test case, test suite and project properties for setting and getting their data through the script. Here are the samples for retrieving the property data.

def getTestCasePropertyValue =
testRunner.testCase.getPropertyValue( "LocalPropertyName" )
def getTestSuitePropertyValue =
( " LocalPropertyName " )
def getProjectPropertyValue =
( " LocalPropertyName " )

In order to access a global property, this is the script:

def getGlobalPropertyValue =
( "GlobalPropertyName" )

These script lines are used to set the value to the local and global property.

testRunner.testCase.setPropertyValue( " LocalPropertyName ", someValue )
testRunner.testCase.testSuite.setPropertyValue( " LocalPropertyName ", someValue )
testRunner.testCase.testSuite.project.setPropertyValue( " LocalPropertyName ", someValue )
( " GlobalPropertyName ", someValue )

Here in these scripts, testRunner is the common object which might be test suites, test cases or project. setPropertyValue and getPropertyValue are the methods or functions.

As we mentioned the above script, we can assign data to the properties.

testRunner.testCase.testSteps[“Properties”].setPropertyValue( “Pro_Response”, testString )

After executing the above script, the property will get updated in the property test step. Refer the following screenshot.

Receiving response data:

Now let us discuss how to get the response data through the script. To do this,

Now SoapUI Pro generates the script as below after specifying the property name.

def response = context.expand( ‘${ServiceRequest#Response}’ )

As we know, “def” is a groovy script keyword that represents defining properties/objects. By default, SoapUI Pro has the property name as “response” in the Get Property popup. If we want we can change this name. Remaining portions of the script are auto-generated.

Let us merge the above script in our earlier discussed script. Here’s what you would see:

def response = context.expand( '${ServiceRequest#Response}' )
testRunner.testCase.setPropertyValue( "Pro_Response", response )
def getLocalPropValue = testRunner.testCase.getPropertyValue("Pro_Response")

If we execute the above script separately, it will log the entire response data in the log section. Even when execute this along with the test case, it will show the same output in the script log.

Creating properties from the navigator pane:

There is another way to create properties locally through the property panel which will appear when we click on the nodes under the project tree. Let’s see how:

 def getPropValue = context.testCase.NetSuite.getPropertyValue(“FromCurrencyValue”)

This script gets the property value and assigns to the variable “getProValue”. To print the value of the property, we can write the following script : (getPropValue);

Global Properties:

Now let us discuss global properties. These properties are defined in one place and we can access them across the project components like test suite, test case, test steps etc.

Here are the scripts for writing data to the global properties.

( "prjFromCurrency", "USD" )
( "prjToCurrency", "INR" )

Once we execute the above test step script, the mentioned properties will be created and the respective values will be assigned to those properties. Let us see how we can verify it.


Properties are helpful for transferring the data between the test steps such as test suites, test steps and test cases. Property can be defined through a groovy script. We can also assign and retrieve data of the properties through the script. And, just like other test steps we can rename or delete or disable the property test step by right click and then choose the respective options from the context menu.

In the next tutorial, we will learn more features about properties like passing properties in the input request and retrieve from global properties, property transfer test step and so on.

Please stay with us and let us know in case of any questions or comments.