Forum Discussion

Venkatraj's avatar
Venkatraj
New Contributor
7 years ago

Setting REST request properties

is it possible to set REST request properties programatically using groovy script ?, If so please provide the snippet 

4 Replies

  • JHunt's avatar
    JHunt
    Community Hero

    Here's a few things you can try:

     

    import com.eviware.soapui.impl.rest.RestMethod
    import com.eviware.soapui.impl.rest.RestRequestInterface.HttpMethod
    import com.eviware.soapui.impl.rest.RestResource
    import com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep
    
    RestTestRequestStep step = testRunner.testCase.getTestStepByName("Some RestTestRequestStep")
    step.testRequest.setEndpoint("http://www.example.com/")
    
    // change to another existing Resource/Method in your project
    RestMethod anotherMethod = testRunner.testCase.project.interfaces["Swagger Petstore"].resources["/pet"].getRestMethodByName("addPet")
    step.setRestMethod(anotherMethod)
    
    // you can update the method used by the step, but be aware that it will affect all requests and test requests using that method
    RestMethod method = step.testRequest.restMethod
    method.setMethod(HttpMethod.GET)
    
    // you can update the resource used by the step, but be aware that it will affect all requests and test requests using that resource
    RestResource resource = method.resource
    resource.setPath("/login")
  • avidCoder's avatar
    avidCoder
    Super Contributor

    Hey,

     

    You could set the properties like this:-

     

    def request = context.expand(${Rest Request#Request})

     

    testRunner.testCase.testSteps["Properties"].setPropertyValue("Rest Request", request)

     

    So, Using this code you are setting the Rest Request to Properties.

     

    Hope this helps you out.

  • nmrao's avatar
    nmrao
    Champion Level 3
    Would you please elaborate the issue, possibly with help of screen shot
    • Venkatraj's avatar
      Venkatraj
      New Contributor

      Thanks for your reply. I want the hilighted rest request properties in the screenshot to be set through groovy script. like (Resource,Method,Endpoint etc.) 

       

       

       

       

       ough groovy script