cancel
Showing results for 
Search instead for 
Did you mean: 

ReadyAPI - How to access the entire request and response from a Groovy script?

SOLVED
rajs2020
Frequent Contributor

ReadyAPI - How to access the entire request and response from a Groovy script?

Inside a groovy test step, is it possible to access the entire request and response data from a previous REST API test step? If yes, then how do we access the request and response?

1 ACCEPTED SOLUTION

Accepted Solutions
HimanshuTayal
Community Hero

Re: ReadyAPI - How to access the entire request and response from a Groovy script?

@rajs2020 : Yes it is possible to get the request and response of any test step refer below code sample:

 

def request = testRunner.testCase.getTestStepByName("TEST__STEP__NAME").getPropertyValue("Request")
def response = testRunner.testCase.getTestStepByName("TEST__STEP__NAME").getPropertyValue("Response")

log.info request
log.info response

Let me know in case more help you needed.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

3 REPLIES 3
HimanshuTayal
Community Hero

Re: ReadyAPI - How to access the entire request and response from a Groovy script?

@rajs2020 : Yes it is possible to get the request and response of any test step refer below code sample:

 

def request = testRunner.testCase.getTestStepByName("TEST__STEP__NAME").getPropertyValue("Request")
def response = testRunner.testCase.getTestStepByName("TEST__STEP__NAME").getPropertyValue("Response")

log.info request
log.info response

Let me know in case more help you needed.

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

rajs2020
Frequent Contributor

Re: ReadyAPI - How to access the entire request and response from a Groovy script?

I realized that there is another, more common way to access the request/response via the UI options.
Open groovy script > Right click > Get data > Select the test case step which has the API call > Select request/response etc.

 

def request = context.expand( '${YourAPICallStep#Request}' )

The "request" is type of class java.lang.String. To convert a Json string to groovy objects, we can use JSON slurper library - https://groovy-lang.org/json.html.

 

rajs2020
Frequent Contributor

Re: ReadyAPI - How to access the entire request and response from a Groovy script?

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors