Forum Discussion

shubhimu's avatar
shubhimu
Contributor
7 years ago

How to run rest requests dynamically using groovy

Hi All,

 

My requirement is to run rest get and post methods requests dynamically using groovy.

 

I have some rest templates in one test case lets say A and have one template placed in other test case lets say B. All i want is want to copy the endpoint/resource and parameters of the rest templates one by one placed under A test case and paste it in to the B test case rest template and run it.

 

Can anyone help here with sample groovy?

 

Thanks,

Himanshu

  • Lucian's avatar
    Lucian
    Community Hero

    I think you might be better of using properties. I just wrote an article on that at:

     

    https://community.smartbear.com/t5/SoapUI-Pro/Properties-in-SoapUI-case-study/m-p/168195#M38070

     

    So for instance you can have 3 project properties like:

    Both the RestServiceA and RestServiceB can have the endpoint set to ${#Project#dynamicEndpoint}. Now let's say you would want to run RestServiceB with the endpoint from RestServiceA and then run RestServiceB with the endpoint from RestServiceB... the following would be the flow:

    1. set dynamicEndpoint = endpointRestA

    2. run RestServiceB

    3. set dynamicEndpoint = endpointRestB

    4. runRestServiceB one more time

     

    Hope this helps!