[英]set rule custom JSR223 Assertion and validate response using Jmeter
你好,有人可以帮助我,我正在验证 api 的响应,我需要验证 3 个测试中至少有一个是正确的,这个 api 执行 3 个请求
var dataStr = prev.getResponseDataAsString();
var data = JSON.parse(dataStr);
if(data.IsSuccessful == true) {
AssertionResult.setFailure(false);
}
else {
AssertionResult.setFailure(true);
AssertionResult.setFailureMessage('fail');
}
ResponseApi Post
{
"IsSuccessful":false,
"IsError":true,
"ErrorMessage":"Error"
}
IsSuccessful 表示响应是否成功https://i.stack.imgur.com/yyI7i.png
I don't think you have JSON.parse()
function in JMeter even if you choose javascript
as the language, switch to groovy
and replace first lines of your assertion code to:
def data = new groovy.json.JsonSlurper().parse(prev.getResponseData())
更多信息:
如果您需要更多帮助(您的“验证 3 项测试中的至少一项为真”声明不清楚) - 考虑使用来自 API 的完整响应数据更新您的问题,并指明您的自定义通过/失败标准
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.