2

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 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Dmitri T and Janesh Kodikara... This worked (y)
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.