swprabhu
7 years agoOccasional Contributor
Reading nodevalues in Json
How to assert the value of a repeated response element
i'm trying to assert for a specific response element from a REST request. The response can contain up to 20 results within the one one response e.g
"totalCount": 1375,
"results": [
{
"title": "florence italy may 12 ryder ...",
"metadata": {
"caption": "florence italy may 12 ryder ...",
"standard.license": "RF",
"base.thumb_large.width": "100",
"base.thumb_large.height": "150",
"base.thumb_small_width": "67"
}
},
{
"title": "Title number 2...",
"metadata": {
"caption": "florence italy may 12 ryder ...",
"standard.license": "RF",
"base.thumb_large.width": "100",
"base.thumb_large.height": "150",
"base.thumb_small_width": "67"
}
},
{
"title": "Title number 3 ...",
"metadata": {
"caption": "florence italy may 12 ryder ...",
"standard.license": "RF",
"base.thumb_large.width": "100",
"base.thumb_large.height": "150",
"base.thumb_small_width": "67"
}
},
I can assert of the existence of say the first occurrance of caption but as the number of results within the one response can vary, is there any way I can check that caption exists in all of the result elements within the one response?
In other words if the request returns 15 results within the one response, how can I assert that each of those 15 results contains the element 'caption' ?
I want to use groovy scripting or if there is any other method , I would like to the commands/syntax . My main question is on how to use JsonSlurper for this .
i'm trying to assert for a specific response element from a REST request. The response can contain up to 20 results within the one one response e.g
"totalCount": 1375,
"results": [
{
"title": "florence italy may 12 ryder ...",
"metadata": {
"caption": "florence italy may 12 ryder ...",
"standard.license": "RF",
"base.thumb_large.width": "100",
"base.thumb_large.height": "150",
"base.thumb_small_width": "67"
}
},
{
"title": "Title number 2...",
"metadata": {
"caption": "florence italy may 12 ryder ...",
"standard.license": "RF",
"base.thumb_large.width": "100",
"base.thumb_large.height": "150",
"base.thumb_small_width": "67"
}
},
{
"title": "Title number 3 ...",
"metadata": {
"caption": "florence italy may 12 ryder ...",
"standard.license": "RF",
"base.thumb_large.width": "100",
"base.thumb_large.height": "150",
"base.thumb_small_width": "67"
}
},
I can assert of the existence of say the first occurrance of caption but as the number of results within the one response can vary, is there any way I can check that caption exists in all of the result elements within the one response?
In other words if the request returns 15 results within the one response, how can I assert that each of those 15 results contains the element 'caption' ?
I want to use groovy scripting or if there is any other method , I would like to the commands/syntax . My main question is on how to use JsonSlurper for this .