我正在寻求有关如何在成功获得响应后在控制器循环时中断的帮助。
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分,它应该会失败。
答案 0 :(得分:0)
将Regular Expression Extractor添加为API请求的子项,并按以下方式进行配置:
这将提取API HTTP Status code并将其存储到${responseCode}
变量中
修改您的While Controller的条件以使用以下__jexl3() function
${__jexl3(${__jm__While Controller__idx} < 5 && "${responseCode}" != "200",)}
就是这样,假设完成上述设置,您的While控制器将在两种情况下损坏:
200