Forum Discussion

padmanabam's avatar
padmanabam
New Contributor
9 years ago

Groovy script for dynamically getting and setting Resource property of REST TEST REQUEST PROPERTY

Hi,

 

Can anyone help me in how to access the Resource property of Rest TestRequest using groovy scripting? I have the requirement for dynamically updating the Resource property of REST TEST REQUESTPROPERTY but we are not using Pro version, we are using opensource 4.5. Can anyone help me in how to access that Resource property and update it again using groovy scripting. I am in great need for that snippet. Help is greatly appreciated. Thanks in advance.

 

 

4 Replies

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    REST requests have quite a fixed format as I am sure you're aware.

     

    To set the enpoint property, its quite easy using a property expansion e.g.

     

    GroovyTestStep (before REST Request TestStep)

     

    context["host"]="localhost"

     

    then in the REST Request TestStep you can get use the value of the host variable to set all or part of the endpoint e.g.

     

    http://${host}:7070

     

    If you mean how to set the resource, I'm sure this is possible by somehow updating the object model of the TestStep, but I find it easier in these situations to instead use an HTTP Request TestsStep, where you are able to control the full URL by using a property expansion like above e.g.

     

    In the Request URL property put something like http://localhost:7070/${context} or simply set the whole url using a property expansion set in a previous TestStep.

     

    Hope this helps,

     

    Cheers,

    Rup

    • padmanabam's avatar
      padmanabam
      New Contributor

      Hi,

       

      Thanks for responding. I parameterized the resource url using Project level properties and I am able to successfully construct the dynamically URL. Thanks