Forum Discussion

mgroen2's avatar
mgroen2
Super Contributor
6 years ago

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

 

 

I have tried several approaches but got lost :(

 

anyone help me with this?

  • Radford's avatar
    Radford
    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.

  • ricardo_moura's avatar
    ricardo_moura
    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