Search code examples
performancejmeterloadjsonassert

JMeter json path assert json or array in the response


I am doing api testing with Jmeter and using json path assertion to the response body. Problem is response body is giving two response path based on success and failure.

for failure

{
    "response": {
        "error_message": "Invalid input data.",
        "error_code": "Invalid_input",
        "error": true
    }
}

for success

{
    "response": [
        {
            "attachment_name": "num1.png",
            "attachment_id": 2547,
            "error": false
        },
        {
            "attachment_name": "num2.png",
            "attachment_id": 2548,
            "error": false
        },
        {
            "attachment_name": "num3.png",
            "attachment_id": 2549,
            "error": false
        }
    ]
}

Here am adding assertion on "error" path and value but the path changes on the result. Added $.response.error but this works only for failure case

enter image description here

Please help me to get correct path and assert in both the conditions. Thanks.


Solution

  • You can use deep scan operator .., the relevant JSON Assertion configuration would be something like:

    enter image description here

    whenever you get error JSON attribute with the value of true the Assertion will fail the relevant Sampler(s) in its scope