I am new to SuapUI and I am trying to use the Contains assert to verify that a certain string exists in a response. I know I can match the value I am looking for with a JSONPath match ($.data[0].ratu_desc), but the value might not always be in the same position (0).
I merely want to verify that the string "ratu_desc": "Total Canada" exists in the response.
What regex should I use? Even when I go to the online regex testers to test my regex pattern, when I paste the pattern into the Contains box it matches nothing.
My JSON response:
{
"data": [
{
"ratu_id": 247796211,
"ratu_desc": "Total Canada",
"ratu_code": "CAN",
"ratu_isarchived": 0,
"ratu_ratm_id": 247795404,
"ratu_ratm_id_lookup": "Audience",
"ratu_slu_id_markettype": 124330,
"ratu_slu_id_markettype_lookup": "Uses Market Allocation Methods",
"ratu_slu_id_estimatetype": null,
"ratu_slu_id_estimatetype_lookup": null
},
{
"ratu_id": 257213831,
"ratu_desc": "SQA Universe",
"ratu_code": "SQUNV",
"ratu_isarchived": 0,
"ratu_ratm_id": 247795993,
"ratu_ratm_id_lookup": "Edmonton EM",
"ratu_slu_id_markettype": 124320,
"ratu_slu_id_markettype_lookup": "Has Market Level estimates",
"ratu_slu_id_estimatetype": null,
"ratu_slu_id_estimatetype_lookup": null
},
],
"error": null,
"bvError": null
}
@mehdihs : You can write custom script assertion i think with pre-available features it is not possible.
Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓
if the regex can't match a string in a response, what does it actually do?
Hi,
add the following JSONPath Expression:
$.data[?(@.ratu_desc=='Total Canada')].ratu_desc
and the Expected Result should be set to:
[Total Canada]
Then it does not matter where "Total Canada" is found, as long as the structure does not change.
You can read more about this here:
https://support.smartbear.com/readyapi/docs/testing/assertions/reference/property/json-match.html
Subject | Author | Latest Post |
---|---|---|