Forum Discussion

sonya_m's avatar
sonya_m
SmartBear Alumni (Retired)
5 years ago

[TechCorner Challenge #16] Compare an expected JSON value and actual response in Events

Hello ReadyAPI Сommunity!

 

We are bringing more awesome tasks your way🙂 Check out the participation rules and the TechCorner Leaderboard here.

 

In this task, we will have a scenario where you will be comparing an expected JSON value from your Data Source and the actual JSON response. This can be done in a separate Groovy Script test step or in the Script assertion but for this task, we are asking you to do so in the RequestFilter.afterRequest event.

 

Task: Compare an expected JSON and actual response in the event

Difficulty: 

 

In your script, you will be fetching the expected response from your Data Source and your JSON response, and then, parsing the JSON to compare their values.

 

JSON response example

Expected JSON value (stored in the DataSource test step)

{
	"id": 1111,
	"name": "doggie",
	"photoUrls": [
		"string"
	],
	"tags": [
		{
			"id": 99,
			"name": "string",
			"Additional info": [
				{
					"ad1": "string",
					"ad2": "string"
				}
			]
		}
	],
	"status": "available"
}
{
	"id": 1111,
	"category": {
		"id": 0,
		"name": "string"
	},
	"name": "doggie",
	"photoUrls": [
		"string"
	],
	"tags": [
		{
			"id": 99,
			"name": "string"
		}
	],
	"status": "available"
}

 

 

 

Here's hint: https://smartbear-cc.force.com/portal/KbArticleViewer?name=How-Do-I-Compare-Two-Dynamic-JSON-Responses&sp=all