Path contains comparison
June 03, 20201 minute read
The path_contains
does the same check as contains
but allows the check to be made inside JSON object path at any depth. The path accessing pattern follows javascript object accessing patterns.
Syntax
{
...
"expect": {
"body": {
"path_contains": {
"path": "value",
"path.key1.key": "value"
}
}
}
}
Example
The api has following response.
{
"people": [
{
"name": "ram",
"age": 20
},
{
"name": "Shyam",
"age": 21
}
]
}
To test using path_contains
check:
{
...
"expect": {
"body": {
"path_contains": {
"people[0]": {
"name": "ram",
},
"people[1].name": "Shyam",
"people": []
}
}
}
}
Note: If a path is not found, the value is always
null
. If you have a response withnull
values consider adding the path key inhasKey
check as well to see if the key is present or not. Combining withhasKey
will ensure the field is present and isnull
.
General use cases
- The same uses case as
contains
check but with the ability to compare at any depths.