问题描述
我有一个while控制器,它重复相同的请求,直到满足条件为止.在此控制器内,我想根据.
I have a while controller that repeats the same request until a condition is met. Inside this controller, I want to select a specific HTTP request depending on a JSON response given by a GET request outside the while loop.
因此,我的逻辑是设置一个while控制器(当前正在工作)
Hence my logic is to set up a while controller (currently working)
${__javaScript(parseInt(${counterApis})<=parseInt(vars.get("FirstNames_matchNr")),)}
内部具有一个JSR223预处理器,其中包含以下内容:
which inside has a JSR223 PreProcessor with the following:
vars.put("TypeCode",vars.get("TypeCodes_"+vars.get("counterApis")));
想法很简单,while循环使用预处理器检查变量TypeCode的值(取决于JSON响应,它可以是ADT,CHD或INF),然后使用此变量来根据此变量在特定的POST请求之间进行选择.
The Idea is simple, the while loop uses the preprocessor to check the value of the variable TypeCode (which can be ADT, CHD or INF depending on the JSON response) and then use this variable to select between a specific POST request depending on this variable.
问题:由于某些原因,当我尝试在while控制器内添加IF CONTROLLER或SWITCH CONTROLLER时,脚本崩溃,无法访问任何POST请求.
The Problem: For some reason when I try to add an IF CONTROLLER or a SWITCH CONTROLLER inside the while controller, script crashes an does not access any of the POST requests.
它是这样的:
推荐答案
您使用了错误的JSR223测试元素. JSR223预处理程序将在之前采样器中执行,因此您的Switch Controller根本不会接收到必要的输入.
You're using wrong JSR223 Test Element. JSR223 PreProcessors are being executed before samplers so your Switch Controller simply does't receive necessary input.
将JSR223预处理器更改为 JSR223采样器,我相信您的脚本将启动按预期工作.如果您不想在测试结果"中看到JSR223采样器,则可以将以下行放在某处:
Change JSR223 PreProcessor to JSR223 Sampler and I believe your script will start working as expected. If you don't want to see the JSR223 Sampler in Test Results you can put the following line somewhere:
SampleResult.setIgnore()
还可以考虑在While控制器中切换为 __groovy()函数 建议使用效果最佳的脚本选项
Also consider switching to __groovy() function in your While Controller as it is recommended to use the most performing scripting option
这篇关于内部控制器,而jmeter中的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!