Transfer Value to Property

Naturally you want to capture a value and send it to a testSuite property or elsewhere.
Rule of thumb is always remember PATH!
SoapUI has a “project” followed by “testSuite” then “testCase” and “testStep“.  That is your path always.  There is one more item you need to remember “testRunner“, which is used in scripting within a Groovy testStep which I’ll explain below.

Again in simple terms: project.testSuite.testCase.testStep
You’ll notice in scripting this path will work backward for the reason of reading from your starting point.

Let’s Start simple: There are two ways to write the path. One is just cleaner. getTestTestSuiteByName is more of a lookup but by all means not slower.

1. Transfer from a TestSuite (Setup or TearDown Script) to TestSuite property
     Syntax 1: testSuite.project.testSuites[“TestSuiteName”].setPropertyValue( “PropertyName”, “ValueToSend” )
Syntax 2: testSuite.project.getTestSuiteByName(“TestSuiteName”).setPropertyValue( “PropertyName”, “ValueToSend” )

Example: I clear values in my [SUBSCRIBE] TestSuite from my [SETUP] TestSuite:
testSuite.project.testSuites["SUBSCRIBE"].setPropertyValue( "firstName", "" )

Note: I don’t use the def for the property name for a very good reason. For example someone may type:
def fName= context.expand( ‘${#TestSuite#firstname}’ ) and use this in the .setPropertyValue( fName, “” )
Why is this not good? Because you may share SoapUI development and if someone deletes a value in the property, you’ll get a null pointer in your script and you have to find it. But using the “quote” name – it will re-write it if that happens.

2. Transfer from TestSuite to TestSuite using a Groovy Script “Teststep”
HUH? Lets say you used a [Property Transfer] Step. You ‘transferred’ this value from your [Teststep] to your [TestSuite] property. But you want to use this value in another TestSuite. For example what I do is create a testCase at the end of my TestSuite called [Transfer_Values] and use the following:

Sending AddressLine1 in SoapUI Pro I use GET DATA (Free Version just copy and paste #1 and change the name):

  1. def Addr1 = context.expand( '${Properties#addressLine1}' )
  2. testRunner.testCase.testSuite.project.getTestSuiteByName("TestSuiteName").setPropertyValue( "PropertyName", Addr1 )

In short, your context.expand will pull your addressLine1 from Properties of your testSuite. The ‘def’ name (whatever you want it to be but keep it unique, you can reuse it in the same script)… I have my def named Addr1 – NOTE that it’s not in quotes in the above code. Quotes is what YOU want it to be, No Quote is pointing to a context.

2. Transfer from TestSuite to Multiple TestSuites via “Teststep”
This makes code much cleaner. You can have a bunch of the same line just with a different testSuite names like:

  1. def Addr1 = context.expand( '${Properties#addressLine1}' )
  2. testRunner.testCase.testSuite.project.testSuites["TestSuite-1"].setPropertyValue( "addressLine1", Addr1 )
  3. testRunner.testCase.testSuite.project.testSuites["TestSuite-2"].setPropertyValue( "addressLine1", Addr1 )

Thank works fine if you want, can make for deleting full lines easily if you remove a testSuite in general. But a cleaner way is like this:

First define you testSuites at the top:

def SUBSCRIBE = testRunner.testCase.testSuite.project.testSuites["SUBSCRIBE"]
def EXISTING = testRunner.testCase.testSuite.project.testSuites["EXISTING"]
//---Then below one line can handle a transfer---------
def FName = context.expand( '${#TestSuite#firstName}' )
     (EXISTING)&&(SUBSCRIBE).setPropertyValue( "firstName", "value" )
def LName= context.expand( '${#TestSuite#lastName}' )
     (EXISTING)&&(SUBSCRIBE).setPropertyValue( "lastName", "value" )

Transfer Value from within a Script Assertion

messageExchange.modelItem.testStep.testCase.testSuite.setPropertyValue( "HouseholdFPL" , result )

//—Note:  The above cannot send a result that contains a numerical value like a BigDecimal…  You have to conert that to a String value.  For example:  def result = (( 26950 / 11670)*100).toDouble().round(3) as String