SoapUI Cheat Sheet: Properties

Most of this can be found on the SoapUI website. This sheet is all about setting, getting, assigning properties in SoapUI via Groovy scripts.

Referencing Properties from within Test Requests

//TestCase level

//TestSuite level

//Project level

Getting Properties…

-From a Groovy Script test step:

def testCaseProperty = testRunner.testCase.getPropertyValue("MyProp")
def testSuiteProperty = testRunner.testCase.testSuite.getPropertyValue("MyProp")
def projectProperty = testRunner.testCase.testSuite.project.getPropertyValue("MyProp")
def globalProperty = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("MyProp")

-From a Script Assertion on a test request:

def testCaseProperty = messageExchange.modelItem.testStep.testCase.getPropertyValue("MyProp")

Setting Properties…

-From a Groovy Script test step:

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)

-From a Script Assertion on a test request:

messageExchange.modelItem.testStep.testCase.setPropertyValue("MyProp", someValue)

-Set Test Suite property to a Json object from Script Assertion

//add a test suite property for a JSON object from a response of a given test case
//builder is the var of your JSON builder which is most likely 'jsonizing' a map
messageExchange.modelItem.testStep.testCase.testSuite.setPropertyValue("SomeObject", JsonOutput.prettyPrint(builder.toString()))

Assign Test Case properties to a map from Groovy Script test step

def tcProps = testRunner.testCase.getProperties()
def map = [:]

//grab all the properties from the test case and put them in a map as long as they aren't empty
for(p in tcProps){		
 			if (p.value.getValue() != "") { 
 			map.put(p.key, p.value.getValue()) 				

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s