简体   繁体   English

Jmeter:如果在响应Cookie中找不到特殊字符串,则调用HTTP采样器请求

[英]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请求?

  1. Approach using While Controller and Counter combination: 使用While控制器计数器组合的方法:

    • While Controller: condition ${__javaScript(${counter} < 5 && "${foo}" != "bar",)} While Controller:条件${__javaScript(${counter} < 5 && "${foo}" != "bar",)}
      • Counter: Start 1 , Increment 1 , Reference Name counter 计数器:开始1 ,增量1 ,参考名称counter
      • Your Sampler 您的采样器

    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控制器

  2. 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.

相关问题 HTTP请求采样器失败时运行的JMeter Beanshell采样器 - JMeter Beanshell sampler that runs when HTTP Request Sampler fails 如何扩展Jmeter Http Sampler在请求中注入auth令牌? - How to extend Jmeter Http Sampler to inject auth token in request? 在 Jmeter 中,如何等待前一个采样器(JDBC 请求)完成,然后启动新的采样器请求(Http 请求) - In Jmeter , how to wait for a previous sampler(JDBC Request) to finish and then start the new sampler Request(Http request) 如何将api的响应传递给jmeter中的junit请求采样器? - How to pass a response of a api to junit request sampler in jmeter? 在http GET请求jmeter中传递cookie - Pass cookie in http GET request jmeter 在JSR223 Sampler Jmeter中添加前一个采样器的Cookie - Adding Cookie from previous sampler in JSR223 Sampler Jmeter 如何使用 JAVA/Groovy 从 Jmeter HTTP 采样器中删除空的 HTTP 请求参数 - How to remove empty HTTP request params from Jmeter HTTP sampler with JAVA/Groovy 如何在Jmeter中将变量从sampler1响应传递到sample2请求 - How to pass variables from sampler1 response to sample2 request in Jmeter 如何在生成某些HKSTD ID的JMeter中使用Java代码? 此ID将在其他http请求采样器中使用 - How to use Java Code in JMeter which generates some HKSTD id ? This id will be use in further http request sampler JMeter ClassNotFoundException on Java 请求采样器 class - JMeter ClassNotFoundException on Java Request Sampler class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM