cancel
Showing results for 
Search instead for 
Did you mean: 

ReadyAPI get content of RAWResponse with groovyscript

SOLVED
Highlighted
Frequent Contributor

ReadyAPI get content of RAWResponse with groovyscript

Hello,

 

I need some developers who could help me here please. Here is what I'm expecting to happen:

 

Run Rest request and read the raw response to get an ID in it

Raw response = 

 

 

HTTP/1.1 200 OK
Date: Wed, 29 Jul 2020 09:09:57 GMT
Server: Apache/2.4.6 (Red Hat Enterprise Linux) OpenSSL/1.0.2k-fips
Max-Forwards: 20
ServiceInfo: {"fsbTransactionId": "XyE85YTg-DP5PlBHXlhwZwAAAEg","ConsumerID": "CD-test.bosa.be","ConsumerInfo": "CD-test.bosa.be=685hsnTrSKw5XZdF","ProviderID": "Notary","ProviderInfo": "Notary=d2313ee0-9bf3-43c4-ae2f-ce736c57f024","ProviderStatus": "Notary=200","BackendTime": "Notary=D=496820","ApplicationID": "2107e608-d6fc-4ff4-91ca-01e1975c3171","ApplicationName": "UNIT.DIS.NAME"}
X-RateLimit-Limit: name=partner,100;
X-RateLimit-Remaining: name=partner,99;
Content-Type: application/json;charset=UTF-8
Keep-Alive: timeout=15, max=499
Connection: Keep-Alive
Transfer-Encoding: chunked

 

 

I need to assert that some strings are present and doesn't contain e.g. "N/A" or are empty.

 

How can that be done please?

Thanks in advance,

AboveAndBeyond

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Leader

Re: ReadyAPI get a file on a website with groovyscript

@AboveAndBeyond :

 

Sorry, i understand it incorrectly, you said raw response but as that ID is coming into 1 of the headers.

 

You can use below updated groovy code to fetch ID:

 

import groovy.json.JsonSlurper

def jsonSlurper
testRunner.testCase.getTestStepByName("Rest Request").testRequest.response.responseHeaders.each { 
	if (it.key == "X-BOSA-ServiceInfo")
		jsonSlurper = new JsonSlurper().parseText(it.value)
}
def applicationID =  jsonSlurper.ApplicationID
assert applicationID != "" : "applicationID is blank"
assert applicationID != null : "applicationID is null"
testRunner.testCase.setPropertyValue("id",applicationID.toString())

 

For UI part you can refer below link:

 

https://learnsoapui.wordpress.com/tag/groovy-script/


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

3 REPLIES 3
Highlighted
Community Leader

Re: ReadyAPI get a file on a website with groovyscript

@AboveAndBeyond :

 

You can refer below code to get ID from raw response and do the assertion on that

 

import groovy.json.JsonSlurper

def response = testRunner.testCase.getTestStepByName("YOUR TEST STEP NAME").getPropertyValue("RawResponse")
def jsonSlurper = new JsonSlurper().parseText(response)
//storing value to local variable
def applicationID =  jsonSlurper.ApplicationID
//asserting application id
assert applicationID != "" : "applicationID is blank"
assert applicationID != null : "applicationID is null"
//storing value to test case level custom properties so can fetch later on
testRunner.testCase.setPropertyValue("id",applicationID.toString())

 

Hope it will help 🙂


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
Highlighted
Frequent Contributor

Re: ReadyAPI get a file on a website with groovyscript

Hello @HimanshuTayal 

 

Thanks for your response, but I get an error message. Maybe I've changed something wrong according my test case or I didn't do so while expected.

See attached screenshot.

Also, this is just to fetch the rawresponse. How could I go to the website to get the file please? I've updated my request 😉 

 

 

Thanks in advance,

AboveAndBeyond

Highlighted
Community Leader

Re: ReadyAPI get a file on a website with groovyscript

@AboveAndBeyond :

 

Sorry, i understand it incorrectly, you said raw response but as that ID is coming into 1 of the headers.

 

You can use below updated groovy code to fetch ID:

 

import groovy.json.JsonSlurper

def jsonSlurper
testRunner.testCase.getTestStepByName("Rest Request").testRequest.response.responseHeaders.each { 
	if (it.key == "X-BOSA-ServiceInfo")
		jsonSlurper = new JsonSlurper().parseText(it.value)
}
def applicationID =  jsonSlurper.ApplicationID
assert applicationID != "" : "applicationID is blank"
assert applicationID != null : "applicationID is null"
testRunner.testCase.setPropertyValue("id",applicationID.toString())

 

For UI part you can refer below link:

 

https://learnsoapui.wordpress.com/tag/groovy-script/


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Compete with community members in the TechCorner Challenge and get into the Leaderboard!

Rank Participant Points Earned
1 msiadak 12
2 nmrao 8
3 HimanshuTayal 3
Top Kudoed Authors