简体   繁体   English

使用 Jmeter 设置规则自定义 JSR223 断言和验证响应

[英]set rule custom JSR223 Assertion and validate response using Jmeter

hello there can somebody help me, I am validating the response of an api, I need to validate that at least one of the 3 tests is true, this api performs 3 requests你好,有人可以帮助我,我正在验证 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 indicates if the response was successful https://i.stack.imgur.com/yyI7i.png 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: 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())

More information:更多信息:

if you need more assistance (your "validate that at least one of the 3 tests is true" statement is not clear) - consider updating your question with full response data from the API and indicate your custom pass/fail criteria如果您需要更多帮助(您的“验证 3 项测试中的至少一项为真”声明不清楚) - 考虑使用来自 API 的完整响应数据更新您的问题,并指明您的自定义通过/失败标准

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用JSR223断言写入文件 - Write to a file using JSR223 Assertion 使用jsr223将JavaScript函数添加到jMeter - Adding javascript function to jMeter using jsr223 如何使用 JSR223 PreProcessor 使用 jmeter 捕获 cookie 值? - How to capture cookie value using JSR223 PreProcessor using jmeter? JMeter-在JSR223 / BeanShell采样器中调用HTTP采样器 - JMeter - Calling HTTP samplers in JSR223/BeanShell samplers JMeter Javascript 语言不适用于 JSR223 Sampler 和 WebDriver Sampler - JMeter Javascript language not available for JSR223 Sampler and WebDriver Sampler 在使用 JMeter 工具进行性能测试期间 - 无法在 JSR223 和 hybrid-crypto.js 中使用 javascript 加密输入值 - During performance testing using JMeter Tool - Not able to encrypt the input values using javascript in JSR223 and hybrid-crypto.js 使用JSR223调用重载静态方法时发生异常 - Exception when calling overloaded static method using JSR223 JMeter JSR 223语言js与javascript - JMeter JSR 223 language js Vs javascript JSR223 Javascript中的回调,Oracle JRE 1.6和OpenJDK 1.6之间的区别(比如安装在Debian上) - Callbacks in JSR223 Javascript, difference between Oracle JRE 1.6 and OpenJDK 1.6 (as installed on, say, Debian) 我可以在Oracle JDK7 JSR223 JavaScript引擎中扩展Java类吗? - Can I extend a Java class in Oracle's JDK7 JSR223 JavaScript engine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM