Jmeter JSON Path Assertion

泪湿孤枕 提交于 2019-12-05 12:55:10

I found the JSR223 Assertion with script language javascript to be the easiest. at least if you have knowledge in java and javascript. And no need to add any plugins.

My working code in detail:

var json = JSON.parse(SampleResult.getResponseDataAsString());
if (json.statusCode != 200) {
    AssertionResult.setFailureMessage("" 
        + json.statusCode 
        + " " + json.statusMessage
        + " " + json.errorMessage);
    AssertionResult.setFailure(true);
}
olyv

I personally prefer to use BSF PostProcessor in coupling with Groovy language. Example of how to parse JSON with Groovy you can find here how to parse json using groovy

For start following JSONPath Assertion will test your statusCode

$.statusCode

put 200 to Expected Value of JSONPath Assertion.

This one is for userName

$.responseData.userName

Easy, isn't it? See Parsing JSON guide for more useful examples and how-tos.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!