SoapUI is a cross-platform functional automation testing tool. SoapUI is free and open source tool and it has been designed to help test APIs such as SOAP and REST interfaces to ensure interoperability of different applications.


SoapUI Pro is the paid version of SoapUI that automatically creates API tests, makes automation easy, and simplifies test maintenance.


SoapUI Groovy Script:

Groovy Script test step is included for custom automation test script creation in SoapUI / Pro.

Groovy is a scripting language which internally includes all the Java libraries, therefore all java related keywords and functions can be used in the groovy script directly. The Java libraries come with SoapUI and are integrated during the SoapUI Pro installation itself.

Imagine you are testing a web service, and you want to run the same test with a different data set. In the SoapUI pro version, you can simply use a DataSource step inside your test case to take data from an external source. Unfortunately, in the free version this kind of step is not available, and the simplest solution would be to create as many test cases as data sets you have, this could work out well if you have ten data sets, but imagine if you have a hundred or more!!

There is a way to work around it, and it is called groovy scripting.

Step #1. In SoapUI,  Create a project, create a test suite with the desired name. Inside the test suite, add groovy script test step as shown below:

Step #2. Enter the name of the step in the dialogue that comes up as below and Clicks OK

Step #3. An editor where you can write your script is displayed. Alternately you can double click on the groovy step name from your test case (Groovy step is the one that has a star prefix to it).


Below script is an example of how to create sample Test Request using Groovy, Run the Request and get the Response.

To Add the Property in Global, project, TestSuite and  TestCase Levels.


To Remove the Property in Global, project, TestSuite and  TestCase Levels.


Set global Property Value:

Get global Property Value:


Set project property value:


Get project property value


Set TestSuite property value:


Get TestSuite property value


Set TestCase property value:


Get TestCase property values:


Set Test Step Property value:

Get TestStep Properties:


Reference property:
#Project# – references a Project property(Reference properties across a particular SoapUI project)

#TestSuite# – references a TestSuite property in the containing TestSuite

#TestCase# – references a TestCase property in the containing TestCase

#MockService# – references a MockService property in the containing MockService

#Global# – references a global property. Found in File>Preferences>Global Properties tab. Reference properties across all projects

#System# – references a system property. Found in Help>System properties.

#Env# – references an environment variable


Print TestSuite and Testcase Names


Get TestSuite Counts


Get TestCase Counts


Get TestStep Counts


Pass the Property value in JSON Requests:



Assert Status Code:


Run Test By Name:

Call Another Test Case using Groovy script

Run the Test Step


Go to Step By Name:

There are many scenarios in which you might want to loop or branch depending on the outcome of some previous TestStep. There are several ways to accomplish this in soapUI;

  1. By using the Conditional Goto TestStep
  2. By creating a Groovy Script TestStep


Read a notepad file:

Below script is an example of how to read the text file.


Write Response in a File:

Below script is an example of how to write the responses in a text file


Set Headers Value to All test steps:

Using the below code we can add headers value to all the requests.


Read and Write in excel sheet

Before run the Script, Download the respective jxl .jar file, place it in SoapUI Lib folder and restart the SoapUI Tool.



Get Property Value of TestCase:

Reading the Property Value by giving Suite name and Testcase name.



Connect to Database:

Before run the Script, Download the respective Sql .jar file, place it in SoapUI Lib folder and restart the SoapUI Tool.

In the below script, Making the Database connections using Postgresql, make sure the correct DB, Username, Password and table.


Case Study:

In the below script Example, Making the POST Request using Groovy Script, Get the Responses and Stored it in TestCase Property level.


In the below script Example, Making the GET Request using Groovy Script, and Validating the Actual and Expected Results of Previous POST example Response.


Reference Links: