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:

Properties in SoapUI

Here are the steps.

  • Right-click on the Test steps node
  • Click Add Step and Properties option from the context menu
  • Enter the property name as desired and click OK
  • In the properties screen, click  properties with groovy Script(1)  icon to add property
  • Enter your desired property name and click OK button. For example, let me enter Pro_Response
  • Type any default value for the property if you wish. For example, I enter “Nothing”
  • Then, add a Groovy Script test step next to the property step. Refer below screenshot.

properties with groovy Script(2)

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.

properties with groovy Script(3)

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")
  • Once written the above script in the editor, double-click on the test case name step.
  • Run the test case by clicking on the iconproperties with groovy Script and the see the results in the script log tab.

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.

properties with groovy Script(4)

Receiving response data:

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

  • Execute the service request once and verify the result
  • Go to Groovy script editor and then right click on the editor as shown in the below screenshot

properties with groovy Script(5)

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:

  • Add currency converter service request and a groovy script test step under the test suite ConversionTestSuite.
  • Click on the TestSuite name under the project (i.e. ConversionTestSuite)
  • At the bottom of the Navigation panel, we can see a Property panel. It contains TestSuite Properties and Custom Properties tabs.
  • Go to Custom Properties tab by clicking on it
  • Then click on the plus ( + ) icon to add the property as shown below:

properties with groovy Script(6)

  • Enter property name and provide default input value as shown in the above screenshot.
  • Now execute the currency converter service request once. Only then we can get the property information when right-clicking on the editor.
  • Enter the following script in the editor

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

  • Click on the Run icon

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.

  • Click on the File menu
  • Then, choose Preferences option
  • In the left side, click on the Global Properties tab.
  • Verify the properties in the property sheet on the right side. Refer the screenshot below:

properties with groovy Script(7)


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.

Recommended Reading

22 thoughts on “How to Use Properties in SoapUI Groovy Script – SoapUI Tutorial #7”

  1. @Sushma: Thanks for reading..

    Randomizing the data source will be discussed in the data driven testing article.

  2. this was a great tutorial and an important step to pass on data between various componeneys in a test case
    Thanks for sharing it

    1) Some problem which can be corrected is :- Space should not be there below
    testRunner.testCase.testSuite.getPropertyValue( ” LocalPropertyName ” )

    2) Can’t we see properties in a table like we see custom properties,, I was not able to see properties defined inside groovy scipt in the form of table in navigation bar on left side

    Keep up the good work.

  3. Hi,

    I tried this sample where Upon execution of below groovi scripts:

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

    I was expecting the value of Pro_Response should be set to TestString but this is not happening.

    can you suggest

  4. in “receiving response data” section on right click am not getting get data option. am using soapui5.2.1

    plz revert on the above

    • Hi
      Thanks for reporting it. It may be a temporary refresh. Can you please try and let us know if the issue still persist? You can try other pages as well.

  5. runner.testSuite.testCaseList.each(){
    for (testStep in it.testStepList)
    testStep.setPropertyValue(“Username”, “dpshud1”)

  6. How to get METHOD from a testStep/testCase/testSuite, basically from any one.

    I am interested to access only GET APIs/testSteps among all type of APIs.

  7. Hello
    This tutorial is very helpful…:) Thanku so much
    But i am getting an error : unexpected char: ‘#’ @ line 1

    Can you please resolve this?

  8. When first adding the property transfer, there is no screen shot of how this is set up. I have attempted to insert the correct source & target details but when I execute that, the Groovy Script is overwritten by the property value. Can anyone help fix this?

  9. What is the difference between context and testRunner. where we use these. In which case we use context and testRunner. I ran the below script. The output is same .

    def getPropValue = testRunner.testCase.testSuite.getPropertyValue(“suite”) “using test tunner “+getPropValue

    def getPropValue1=context.testCase.testSuite.getPropertyValue(“suite”) “using context”+getPropValue1

  10. @hemantvarhekar
    please try this one
    String testString = “TestString”
    testRunner.testCase.setPropertyValue(“Pro_Response”, testString)
    def getLocalPropValue = testRunner.testCase.getPropertyValue(“Pro_Response”)

    There was extra space in the ( “Pro_Response”, testString )

  11. I was wondering how would i use the groovy script to skip between steps in a test suite for example say i wanted to go from step 1 to step 4 and to do so i needed a value from the xml code in step one how would i get that value inside the groovy script in order to go to step four

  12. Hi,
    I need to insert in each Field, All possible Data, suggested on use case with SoapUI

    How can i Do it with Groovy and SoapUI


Leave a Comment