Groovy Data Source

Applies to ReadyAPI 3.7, last modified on April 19, 2021

The Groovy data source generates property values by executing a groovy script.

Tip: To learn how to set up a data source loop and refer to data source properties in your tests, see this topic.

You can use data sources of the Groovy type in the DataSource test step in functional tests. They are not available in virtual services.


The Groovy data source

Click the image to enlarge it.

Tip: If the font of the editor is not comfortable for you, change it by using Ctrl + mouse wheel.

Specify the Groovy code that will generate the desired data. To get an output value, use the built-in result object. It is an associative array, keys of which match the specified properties. For example, the following codesnippet assigns a string to the foo property:


result["foo"] = "bar"

You can use the following objects in your scripts:

  • context – Provides a scripting interface to the properties specific to the current test run context.

  • results – An associative array, keys of which match the data source properties.

  • testRunner – Provides a scripting interface to the test runner object that is executing the current test case and test step.

  • log – Provides a scripting interface to the ReadyAPI test log.

Generating multiple rows per iteration

ReadyAPI runs the data source script as many times as you set in the Rows Per Iteration option. To get a value from a specific row, use the following syntax:


To learn more, see Property Expansion.


The following script returns a list of files in the home directory.

Note: Script returns values to the File property. Make sure you create it before you run the script.


// Import required class

// Get current row
def row = testRunner.testCase.testSteps["GroovyDataSource"].currentRow;

// Get the home user directory
def directoryName = System.getProperty("user.home");

// Declare an array that will contain file names
def fileNames = [];

// Get a list of files in the directory
new File(directoryName).eachFile(FileType.FILES)
    // Add the name of the file to the list
    file -> fileNames.add(;

// Check that the current row number does not exceed the array size
if (row < fileNames.size) {
    // Return the name to data source's "File" property
    result["File"] = fileNames[row];

Here is a sample of the script run:

Sample Groovy run

Click the image to enlarge it.

See Also

Basic Concepts of Data-Driven Testing
DataSource Test Step
DataSource Loop Test Step
Excel Data Source
Data Source Types

Highlight search results