Applies to ReadyAPI 3.3.1, last modified on August 11, 2020

Groovy scripts have access to your project information, including properties, settings, and names of all items in the project. You can modify these from script to suit your needs during the test run, and then set them back to default values.

Availability

There are several ways to run the scripts below:

Get and Set Properties

You can access all properties of ReadyAPI test items from your scripts in the following way:

Groovy

// Get property from a test case
def testCaseProperty = testRunner.testCase.getPropertyValue( "MyProp" )

// Get property from a test suite
def testSuiteProperty = testRunner.testCase.testSuite.getPropertyValue( "MyProp" )

// Get a project property
def projectProperty = testRunner.testCase.testSuite.project.getPropertyValue( "MyProp" )

// Get a global property
def globalProperty = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "MyProp" )

// In Script Assertions, you access test cases in a different way:
// def testCaseProperty = messageExchange.modelItem.testStep.testCase.getPropertyValue( "MyProp" )

// Set values to the same properties.
testRunner.testCase.setPropertyValue( "MyProp", 'someValue' )
testRunner.testCase.testSuite.setPropertyValue( "MyProp", 'someValue' )
testRunner.testCase.testSuite.project.setPropertyValue( "MyProp", 'someValue' )
com.eviware.soapui.SoapUI.globalProperties.setPropertyValue( "MyProp", 'someValue' )

Tip: Have a look at the TestPropertyHolder interface for digging into the object model.

Rename Test Items

Since the test item name is one of the properties, you can change it in your scripts:

Groovy

// Set names for the test case, test suite, and project.
testRunner.testCase.name = 'Sample Test Case Name'
testRunner.testCase.testSuite.name = 'Sample Test Suite Name'
testRunner.testCase.testSuite.project.name = 'Sample Project Name'

Some scripts may get items by their names. If you rename the item, those scripts will fail.

See Also

Data-Driven Testing Tutorials
DataSource Test Step

Highlight search results