Forum Discussion

rajpenumalli's avatar
rajpenumalli
Occasional Contributor
7 years ago

How to get request-URI from raw request content using groovy script

Hi Support,

How to get request-URI from raw request content using groovy script(i want to use this script in groovy step)  

 

I am using READY API 2.2.0.

 

for example in following example i need get  request-URI="/version_1.0.0/login"

 

Following is my Raw request content:

      GET https://demo.app.com/version_1.0.0/login
      Accept-Encoding: gzip,deflate
      Cookie: AC1799C04C5F97FAB7B5AC4E3D355D1741794DD381D43F572DE830AF4111F0CB5161FB
      Content-Length: 0
      Host: demo.app.com
      Connection: Keep-Alive
      User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_144)

 

Thanks,

Rajendra 

 

 

  • avidCoder's avatar
    avidCoder
    Super Contributor

    Use this code to get the endpoint and after that use split() function.

     

    def endPoint = testRunner.testCase.getTestStepByName("Request Name").getHttpRequest().getEndpoint()

  • rajpenumalli's avatar
    rajpenumalli
    Occasional Contributor

    Hi,

    Thanks for quick replay,

    it is giving out put as follows:  ${#Project#server}/version_{#Project#apiVersion}/login

    but i need in raw format like: demo.app.com/version_1.0.0/login

     

    Any idea how to get this?

     

    Thanks,

    Rajendra 

     

     

    • avidCoder's avatar
      avidCoder
      Super Contributor

      Could you please attach the screenshot for this?

    • PaulMS's avatar
      PaulMS
      Super Contributor

      To expand the properties
      log.info context.expand(endPoint)

      • Bill_In_Irvine's avatar
        Bill_In_Irvine
        Contributor

        I can do this in an event handler

         

        String therequestUri = new String(context.getProperty("requestUri").toString())
        log.info "therequestUri is " + therequestUri

        but note it might not be retrievable in the context where you use groovy. Your script might be a test step groovy script, a setup script, or teardown, I don't know...

         

        You can do the following in an assertion script (I just tried it myself)

         

        def endpoint = messageExchange.getEndpoint()
        log.info endpoint

         

        You might get it via a call path from testRunner. I suggest you look for where you can find the "requestUri" property.

         

        Bill