ReadyAPI - How to access the entire request and response from a Groovy script?
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I asked a follow up question here.
https://community.smartbear.com/t5/API-Functional-Security-Testing/Is-there-an-easy-way-to-access-pa...
