Katakana
Katakana

Reputation: 73

Why is Jmeter JSON Assertion successful in this situation?

I'm in need of help understanding how JSON Path assertions work in Jmeter. Given the following JSON,

{
    "isCompressed": true,
    "rows": [
         {
            "_2": "",
            "_4": "CustomString_1401",
            "_5": {
                "latitude": 0.0,
                "longitude": 0.0,
                "elevation": 0.0
            },
            "_6": "CustomString_1401",
            "_8": "User0",
            "_9": "User",
            "_10": [],
            "_11": 1641561103991
        },
        {
            "_2": "",
            "_4": "CustomString_3930",
            "_5": {
                "latitude": 0.0,
                "longitude": 0.0,
                "elevation": 0.0
            },
            "_6": "CustomString_3930",
            "_8": "User0",
            "_9": "User",
            "_10": [],
            "_11": 1641561045657
        }
    ]
}

Any of the following different JSON Path assertions do NOT fail in a JSON Assertion in Jmeter 5.4.3. I'm using just a simple JSON assertion with no value assertion.

$.rows[?(@._4=="Custom")]._4
$.rows[?(@._4=="Custom_3930")]._122

In the case of assertion 1, there is no array element that satisfies that condition. In case of assertion 2, there's no key with that name in there. Why is the assertion successful if those paths do not exist?

Upvotes: 0

Views: 346

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

It sounds like a bug in JMeter connected with presence of the Filter Operators in your query, you should raise it via JMeter Bugzilla

In the meantime you can switch to JSR223 Assertion and Groovy language, the equivalent code would be something like:

def result = com.jayway.jsonpath.JsonPath.read(prev.getResponseDataAsString(), '$.rows[?(@._4=="Custom")]._4')

if (result.size() == 0) {
    AssertionResult.setFailure(true)
    AssertionResult.setFailureMessage('There were no nodes matching the Json Path query')
}

Upvotes: 2

Related Questions