简体   繁体   中英

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

  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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM