Forum Discussion

lichle's avatar
lichle
New Contributor
8 years ago

Groovy get whole requesturi

Hello, 

 

I would like to retrieve the whole requesturi using groovy. 

My example is like this: 

endpoint: http://api.test.com/abc

Resource: /def/guest/{guestid}

 

My request header is: 

GET https://api.test.com/abc/def/guest/52 HTTP/1.1
Accept-Encoding: gzip,deflate
Host: api.dapaws.foliofn.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_102)

 

I would like to get the full requesturi to use in my groovy script as :https://api.test.com/abc/def/guest/52

 

Thanks in advance.

 

3 Replies

  • avidCoder's avatar
    avidCoder
    Super Contributor

     

    You can try this code to get the endpoint with resource:-

     

    def testStep = testRunner.testCase.getTestStepByName("REST_REQUEST_NAME");
    
    String EndPointUrl = testStep.getHttpRequest().getEndpoint();
    String path = testStep.getHttpRequest().getPath()
    String url = EndPointUrl+path
    String requestMethod = testStep.getHttpRequest().getMethod();
    
    log.info(url)
    log.info(requestMethod)