how to transfer result of groovy script

Originally posted by mgroen2 on January 17, 2019

I have following Groovy script in Ready:

def profiel = UUID.randomUUID()

this generates a UUID as the script result

Now I want to use the value of profiel in the body of another request.

after the text “test” I want it to get inserted

I have tried several approaches but got lost :frowning:

anyone help me with this?

Originally posted by Radford on January 17, 2019

There are a couple of ways depending on your preferred method of working:

  1. You could use a Property Expansion within your other request, to reference a groovy test step result, it will look something like ${Groovy Script#result} where “Groovy Script” is the name of the test step. From within your other step you should be able to use the Get Data point and click functionality function to construct the property expansion for you.

  2. You could put a property transfer test step between the Groovy Script test step and you other request test step.

  3. You could set the data directly from the Groovy script.

My personal preference is number 2, the property transfer step, as it make it very obvious what is going on and where the data is coming from and going to.

Originally posted by ricardo_moura on January 17, 2019

you can use following lines in your groovy script step:

def profiel = UUID.randomUUID()
testRunner.testCase.setPropertyValue("TestCasePropertyName", profiel.toString())

and on next request step, put “${#TestCase#TestCasePropertyName}” where you want the UUID value.

regards

Originally posted by nmrao on January 18, 2019

Actually, groovy script step is not even required for the use case. That can be achieve with in the request itself as shown below:

Assuming that you are using the uuid valud in REST Request test step:

{
   "id" : "${= java.util.UUID.randomUUID()}"
}

For more details, refer documentation

https://www.soapui.org/scripting-properties/property-expansion.html