[英]Jmeter: Recall HTTP sampler request if a particalar string is not found in response cookie
I have to implement a scenario where i have to call the same request at max for 5 times if it fails and based on the response i am writing some thing in a file. 我必须实现一个方案,如果失败,我必须最多调用同一请求5次,并且基于响应,我正在文件中写入一些内容。 Failure happens when a string is not found from cookie which i am capturing as regular exp. 当从cookie中找不到字符串时会发生失败,而我正在捕获它作为常规exp。
To resolve this , i have added while loop with counter but the script works till 50000 iteration and then gives Out of memory error. 为了解决这个问题,我添加了带计数器的while循环,但是脚本可以工作到50000次迭代,然后发出内存不足错误。 If i dont put while loop to recall the same request for 5 times, then same script works for 1 million with same JVM without any issue. 如果我不使用while循环调用5次相同的请求,那么对于具有相同JVM的一百万个脚本来说,相同的脚本没有任何问题。
Looks like While controller in Jmeter is somehow consuming more memory and throwing out of memory. 看起来Jmeter中的While控制器以某种方式消耗了更多内存,并耗尽了内存。
Is there any option to recall the same HTTP request through Beanshell Post processor? 是否可以通过Beanshell Post处理器调用相同的HTTP请求?
Approach using While Controller and Counter combination: 使用While控制器和计数器组合的方法:
${__javaScript(${counter} < 5 && "${foo}" != "bar",)}
While Controller:条件${__javaScript(${counter} < 5 && "${foo}" != "bar",)}
1
, Increment 1
, Reference Name counter
计数器:开始1
,增量1
,参考名称counter
Assuming above setup Your Sampler
will be executed either 5 times or until when ${foo}
variable value not equal to bar
, whatever comes the first. 假设以上设置, Your Sampler
将执行5次,或者直到${foo}
变量值不等于bar
时执行,直到第一个执行。 See Using the While Controller in JMeter for comprehensive explanation and more examples. 有关全面的解释和更多示例,请参见在JMeter中使用While控制器 。
If you are still looking for Beanshell way you can use something like: 如果您仍在寻找Beanshell方式,则可以使用以下方法:
if (!prev.getResponseDataAsString().contains("foo")) { ctx.getCurrentSampler().sample(null); }
Above code being placed into Beanshell PostProcessor will execute the parent sampler one more time if there will not be foo
substring in the response, however this way you won't be able to see execution result in listeners and it won't be stored into .jtl file, basically you will have only one execution. 如果响应中没有foo
子字符串,则上述放置在Beanshell PostProcessor中的代码将再次执行父采样器,但是这种方式将无法在侦听器中看到执行结果,也不会将其存储到中。 jtl文件,基本上您只会执行一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.