AAB
5 years agoRegular 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
AAB :
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: