cancel
Showing results for 
Search instead for 
Did you mean: 

read json responses from test case

SOLVED
Highlighted
Contributor

read json responses from test case

I want to read the two json responses outside the test step under the test case name groovy script using ReadyAPI.

import groovy.json.JsonSlurper
def jsonString1 =context.expand('${aPOST#Response}') //aPOST - response from test case  createApost
def jsonString2 =context.expand('$bPOST#Response}') //bPOST - response from test case createBPost
def json1 = new groovy.json.JsonSlurper().parseText(jsonString1)

def json2 = new groovy.json.JsonSlurper().parseText(jsonString2)

I couldnt read the response with the above option, would like to know the possible ways.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: read json responses from test case

It can be done but as @nmrao said it is usually recommended to keep the test cases separated from each other. Nevertheless here is the code:

 

// Get the test step for which you want the response
def testStep = testRunner.testCase.testSuite.testCases[ "Name of your test case" ].testSteps[ "Name of your test step" ]
// Get the response
def response = testStep.testRequest.response.responseContent
// Log the response
log.info response

I created a demo project which can be downloaded from https://github.com/lucadln/soapui/tree/master/ReadyAPI/ResponseFromDifferentTestCase

 

Cheers! Man Wink



If my answer helped please click on the 'Accept as Solution' button.

View solution in original post

6 REPLIES 6
Highlighted
Community Hero

Re: read json responses from test case

@SK07, what are you observing then? the above should work perfectly.

Have you run the those teststeps already?


Regards,
Rao.
Highlighted
Contributor

Re: read json responses from test case

@nmrao, Yes. I'm reading these responses under a new test case and in a new test step. Note, that the responses are present in a different test case. When I run this, getting the error text as null.

Highlighted
Community Hero

Re: read json responses from test case

It is good practice to have each test case independent. Not quite sure why are you reading the responses from different test cases.


Regards,
Rao.
Highlighted
Community Hero

Re: read json responses from test case

It can be done but as @nmrao said it is usually recommended to keep the test cases separated from each other. Nevertheless here is the code:

 

// Get the test step for which you want the response
def testStep = testRunner.testCase.testSuite.testCases[ "Name of your test case" ].testSteps[ "Name of your test step" ]
// Get the response
def response = testStep.testRequest.response.responseContent
// Log the response
log.info response

I created a demo project which can be downloaded from https://github.com/lucadln/soapui/tree/master/ReadyAPI/ResponseFromDifferentTestCase

 

Cheers! Man Wink



If my answer helped please click on the 'Accept as Solution' button.

View solution in original post

Highlighted
Contributor

Re: read json responses from test case

Thank you @nmrao 

Highlighted
Contributor

Re: read json responses from test case

Thank you! Lucian.

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