通过在JMeter中检查响应正文来停止发送请求 [英] Stop Sending Requests By Checking the Response Body in JMeter

查看:110
本文介绍了通过在JMeter中检查响应正文来停止发送请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想继续调用REST API,直到响应正文包含100个元素.

I want to keep calling to a REST API until the Response Body contains a 100 elements.

这里是示例:

请求:someurl/get/data

响应: 第一次API调用:(包括2个元素)

response : 1st API call : (2elements included)

{
  "items" : [
          {
            "name": "abc",
            "id"  : "ajdiw123"
          },
          {
            "name": "abc",
            "id"  : "ajdiw123345"
          }
  ]
}

第二次API调用:(4个元素)

2nd API call : (4 elements)

{
  "items" : [
          {
            "name": "abc",
            "id"  : "ajdiw123"
          },
          {
            "name": "def",
            "id"  : "ajdiw145"
          },
          {
            "name": "afc",
            "id"  : "ajdiw113"
          },
          {
            "name": "bbc",
            "id"  : "ajdiw199"
          }
  ]
}

像此响应正文一样,

可以更改的元素.在某个时候,它将在那里返回100个具有100个不同id的元素.我该如何识别并停止使用JMeter将请求发送到端点.

like this response body included elements can changed. At some point it will return 100 elements with 100 different ids there. How I can identified that and stop sending the requests to the endpoint using JMeter.

推荐答案

可以根据您的测试计划以多种方式实现.

It can be achieved in multiple ways depending on your test plan.

添加 JSON提取器 JSON提取器设置如下:

JSON Extractor Settings will be like:

JSR223断言代码如下:

JSR223 Assertion code will be like:

String totalIDs = vars.get("id_matchNr");
Integer result = Integer.valueOf(totalIDs);
if (result == 100){
    AssertionResult.setFailure(true);
}

之后,只需向该请求添加结果状态操作处理程序因此它将停止执行特定线程:

After that, just add a Result Status Action Handler to that request so it will stop the execution for the specific thread:

这篇关于通过在JMeter中检查响应正文来停止发送请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆