Forum Discussion

vinay's avatar
vinay
Occasional Contributor
16 years ago

[RESOLVED]How to parameterize/ capture REST GET Request using groovy

I have a REST web service that takes zip code in the URL ( http://testexample.net/weatherbyZipcode/{zipcode}). I would like to populate the zip code from the response of a previous request. So I am writing a groovy script. But I am unable to capture the Request. Unlike SOAP Request this is a GET request and I am having tough time capturing the request. Any ideas please

5 Replies

  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Use a Property Transfer step to select part of the response and move it to a Property, then use a property expansion in the URL?

    Or in a Groovy script you can get the reponse with this:

    testRunner.testCase.getTestStepByName("HTTP Test Request").getHttpRequest().getResponseContentAsXml()

    and then parse out the value you want.

    Or am I misunderstanding what you are looking to do?
  • vinay's avatar
    vinay
    Occasional Contributor
    Donald Thanks for the quick reply. I got the response part figured out since it is an XML file. Now I am trying to read the REST request. Unfortunately REST Requests are GET , PUT and are not XML files. So I am trying to get the groovy script to capture the REST request.
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    How about

    testRunner.testCase.getTestStepByName("REST Test Request").getHttpRequest().getEndpoint()

    Unfortunately it will not expand any property expansions...
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    ... but you can expand it yourself

    context.expand(testRunner.testCase.getTestStepByName("REST Test Request").getHttpRequest().getEndpoint())
  • vinay's avatar
    vinay
    Occasional Contributor
    it worked!!! . Thank you. I got the zip code value by using getPropertyValue("zipcode").