1
votes

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.

2

2 Answers

2
votes

You can use regular expression for verifying both value (true or false) in the JSON Assertion.

enter image description here

A sample test plan is available for reference in GitHub

Hope this is useful.

1
votes

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