【问题标题】:Jmeter- how to break while controller after getting successful repsonseJmeter-在获得成功响应后如何在控制器中中断
【发布时间】:2020-04-18 15:17:37
【问题描述】:

当我得到成功响应时,我正在寻求有关如何打破 while 控制器循环的帮助。

Steps:-
1. I have a while controller where I kept below logic
${__javaScript((${controller} < 5),)}
2. And inside while controller I have created http request which return response.
This request takes some time to give result.if this request is still
running it will return status code 202.. and if this request is completed it will give 200.(I have another API to check this)

So here I dont know when it will get success.
for that after each request I have kept waiting time.
So when I call first time after while loop.. its giving 202(because its still running)
and I will continue this process till 5 times..
So here there is chance I can get 200 success code at 3rd request.
So what I want here is I would like to break the loop after that..I dont want to run till 5 times.

I am using below code to read the response.

if (status_code == "200"){
            AssertionResult.setFailure(false); 
    }

所以当我从响应中得到 200 时,它应该停止并获得成功 如果我在所有 5 次尝试中都没有从响应中得到 200,它应该会失败。

【问题讨论】:

    标签: jmeter


    【解决方案1】:
    1. Regular Expression Extractor 添加为 API 请求的子项并进行如下配置:

      这将提取 API HTTP Status code 并将其存储到 ${responseCode} 变量中

    2. 修改您的 While 控制器的条件以使用以下 __jexl3() function

      ${__jexl3(${__jm__While Controller__idx} < 5 && "${responseCode}" != "200",)}
      
    3. 就是这样,假设上述设置您的 While 控制器将在 2 种情况下中断:

      • 响应码是200
      • API 请求执行 5 次

    更多信息:Using the While Controller in JMeter

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 2015-09-20
      • 1970-01-01
      • 2013-12-30
      相关资源
      最近更新 更多