Forum Discussion

ajay1902's avatar
ajay1902
Occasional Contributor
7 years ago

how to extract "Rest Request properties" via groovy Script from Rest Test step

I need help in trying to extract the Rest Request Properties associated with a Rest Request test step in ReadyAPI via Groovy Script.   Scenario - want to extract the Resource property listed under...
  • Bill_In_Irvine's avatar
    7 years ago

    Well one of the things you requested was how to extract the REST Request properties. 

     

    You can do this in a groovy script in the RequestFilter.filterRequest event handler

     

    https://community.smartbear.com/t5/SoapUI-Pro/Is-there-any-way-to-get-rest-resource-of-a-rest-step-through/m-p/147648#M33627

     

    Now, you say you want to parameterize the resource path. You have 30 APIs. You mean in https://xxx.xxx.xxx.xxx:xxxxx form? It might make sense to use the Environment capability to switch between APIs. 

     

    You can use the Environement to set the custom project property for the resource of that API. Then in Groovy use the property expansion to set the resource My link above "gets" the resource. 

     

    From the context module you probably can use setProperty. You can also drill down to the test case to set the request when everything is all ready. I add stuff to the body of the request and do something  the following in a Groovy test step (not the event handler) 

    def json = …
    def restRequest = testRunner.testCase.getTestStepByName(“my test step name“);
    
    // Set the json for the test step request
    restRequest.setPropertyValue('Request', json.toString())