cancel
Showing results for 
Search instead for 
Did you mean: 

how to transfer result of groovy script

Highlighted
Super Contributor

how to transfer result of groovy script

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

 

2019-01-17_15-12-43.png

 

I have tried several approaches but got lost 😞

 

anyone help me with this?

2019-01-17_15-14-43.png

3 REPLIES 3
Highlighted
Super Contributor

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.

Highlighted
Occasional Contributor

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

 

Highlighted
Community Hero

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



Regards,
Rao.
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors