I wanted to check for the presence of a string in Restful API response.
I did this
def response = WS.sendRequest(findTestObject('Get Status'))
responseText = response.getResponseText()
WS.containsString(response, “completed”, true)
I got the following error
Test Cases/Get Status FAILED because (of) Unable to check contain string (Root cause: Given string ‘completed’ not found in response text
‘{“result”:{“id”:2,“status”:“completed”},“status”:“success”,“code”:200}’)
I can see that response text contains the word “completed”.
Can you help?
Please use assert response.getResponseText().contains("completed"). There is an issue in WS.containsString keyword.
Thanks.
2 Likes
duyluong said:
Please use assert response.getResponseText().contains("completed"). There is an issue in WS.containsString keyword.
Thanks.
hi duyluong, i have similar case
from case at the top,
how can i show response to console
i’m just want to show status":“success”
Thanks
Joko T. Susilo Widodo said:
duyluong said:
Please use assert response.getResponseText().contains("completed"). There is an issue in WS.containsString keyword.
Thanks.
hi duyluong, i have similar case
from case at the top,
how can i show response to console
i’m just want to show status":“success”
Thanks
Hi Joko,
Please take a look at builtin function JsonSurpler of groovy.
There were many similar discussions such as:
Below is the code i am trying to parse a json response def responseText = response.getResponseText() println(responseText ) Result: {“applications”:[ {“name”:“test123”,“id”:“c1257c5”,“description”:“test”,“type”:“generic”,“version”:“0.1”}, ...
Reading time: 1 mins 🕑
Likes: 6 ❤
My json file looks like: // “189”: {“value”:266,“label”:“External Coordinator Course (EXCOORD-HL-EN) (EXCOORD-HL-EN)”}, “162”:{“value”:239,“label”:“First Aid Course (PMP-HL-EN)”}, “54”:{“value”:82,“label”:“First Aid Course (FA-HL-EN)...
Reading time: 1 mins 🕑
Likes: 4 ❤
Hello all, my apologies if this topic was already discussed (could not find such). The question is the following: every time I get a response, I have a kind of data – the list of the franchises with the genres list “inside” every franchise: ...
In the above mentioned case, please try:
def jsonSlurper = new JsonSlurper()def object = jsonSlurper.parseText(response. getResponseText())println object.statusassert object.status == 'success'