Forum Discussion

shubhimu's avatar
7 years ago

How to fetch rest get method request parameters using groovy script



Please tell me the way to fetch rest get method request parameters value using groovy script.


Also is it possible that we can get add parameters using groovy. 


Kindly let me know.

Using below code i am able to get the endpoint, resource but need help in getting the parameters(query string)



def pro=testRunner.testCase.testSuite.project
def tcrest=testRunner.testCase.testSuite.project.getTestSuiteByName("Business Templates").getTestCaseByName("Rest_GetTemplates")
def request =tcrest.getTestStepByName("RequestTemplate_GetPromotions").httpRequest.requestContent
def tcexe=testRunner.testCase.testSuite.project.getTestSuiteByName("Execution Suite").getTestCaseByName("Execution Driver")
def endpoint=tcrest.getTestStepByName("RequestTemplate_GetPromotions").getPropertyValue("EndPoint")
String resourcepath=tcrest.getTestStepByName("RequestTemplate_GetPromotions").getResourcePath() endpoint
tcexe.getTestStepByName("REST Request Get").setPropertyValue("EndPoint", endpoint)
//String resourcepath= tcrest.getTestStepByName("RequestTemplate_GetPromotions").httpRequest.getPath() "Business template resource path is"+resourcepath
tcexe.setPropertyValue("ResourcePath", resourcepath)
catch(Exception e)
log.error " exception message is "+e.getMessage()




3 Replies

  • Lucian's avatar
    Community Hero

    Hey, this should do it:


    // Get the current test case
    def testCase = testRunner.testCase
    // Get the desired testStep
    def testStep = testCase.getTestStepByName("Request1")
    // Iterate through each parameter
    // Log the existing parameters it.getKey() + " : " + it.getValue().getValue() }

    // Add a new parameter called 'param3' and assign to it the value 'val3'
    testStep.getRestMethod().addProperty( "param3" ).setValue( "val3" ) 


    • shubhimu's avatar

      Lucian. Thanks for this.


      My requirement is to take rest request from one test case lets say A and copy the endpoint/resource and parameter of the same in to the rest request placed in another test case B and run the request from B test case.


      Ready api has non editable endpoint/resource/parameter. And i can take the end point of rest request from its custom properties. Also i can set it in the another test case rest request but i am not able to get and set resource and parameters.


      You provoded the solution to get rest request parameters and add it but can you please provide me some help in getting the resource and how i can set it in another request. Also how i can set rest request parameters in another rest request.




      • Radford's avatar
        Super Contributor

        I don't know how to do exactly what you are asking and while not the solution you need this might help you on your way, some Groovy which will get the rest resource details:

         'REST Test Step Class = ' + testRunner.getTestCase().getTestStepByName('REST Request').getClass())
       'Resource Name = ' + testRunner.getTestCase().getTestStepByName('REST Request').getResource().getName())
        def xmlBeansRestParamsTestPropertyHolder = testRunner.getTestCase().getTestStepByName('REST Request').getResource().getParams()
       'xmlBeansRestParamsTestPropertyHolder Class = ' + xmlBeansRestParamsTestPropertyHolder.getClass())
        xmlBeansRestParamsTestPropertyHolder.getPropertyList().each(){ restParamsTestProperty -> 
        '----------------------------------------------')'Param Class = ' + restParamsTestProperty.getClass())'Param Name = ' + restParamsTestProperty.getName())  'Param Style = ' + restParamsTestProperty.getStyle())'Param Location = ' + restParamsTestProperty.getParamLocation())'Data Type = ' + restParamsTestProperty.getType().getLocalPart())


        I assume that you've seen the Ready API JavaDocs? I think this will be a case of looking up the classes in the JavaDocs and trying things out, good luck. Please do post back here if you solve this problem.