簡體   English   中英

使用 Jmeter 設置規則自定義 JSR223 斷言和驗證響應

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM