JMeter While 控制器

发布于 2024-12-11 21:44:17 字数 296 浏览 0 评论 0原文

我在整个网络上疯狂地寻找解决我的问题的方法,但目前还没有。我的问题是,我必须检查是否在 HTTP 请求中获取特定文本,该文本位于 while 循环中,如果是,那么我应该离开循环并继续线程,或者如果文本不存在则完全停止线程。我的设置如下:

Thread Group
.. While controller
   .. HTTP request
      .. Response Assertion
Listener

我在 while 控制器中使用了 LAST 并将 HTTP 响应设置为虚假文本,但它不起作用。

I have searched as crazy for the solution to my problem throughout the web, but none exist yet. My problem is that I have to check if I get specific text in HTTP request, which is in a while loop and if I do, then I should leave the loop and continue with the thread or stop the thread completely if text doesn't exist. I have set it up as follows:

Thread Group
.. While controller
   .. HTTP request
      .. Response Assertion
Listener

I used LAST in the while controller and set HTTP response to false text and it doesn't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陌上青苔 2024-12-18 21:44:17

希望以下内容对您有用:

Thread Group
    HTTP Request
    //set-found-condition
    ${__setProperty(txtFound,FALSE,)}
    While Controller
    // invert value in condition - will be executed while txtFound == FALSE
    Condition = ${__BeanShell(!props.get("txtFound")}
    . . .
    [execute your test logic here]
    . . .
    YOUR HTTP Request
        Response Assertion
        // set your text assertion here
        // this will results in ${JMeterThread.last_sample_ok} = TRUE if text found
    IF Controller    --FOUND
    // if text found set separate variable or property - e.g. ${txtFound} - into TRUE
    Condition = ${JMeterThread.last_sample_ok}
        HTTP Request 
        //set-found-condition
        ${__setProperty(txtFound,TRUE,)}  // this will be inverted to FALSE in the next WHILE cycle's condition, WHILE cycle will be exited
    . . .

我想您也可以轻松使用 JSR / BSF / BeanShell PostProcessor 附加到您的 HTTP 请求,将 txtFound 属性设置为 TRUE,而不是使用 IF 进行繁琐的构造。

Hope the following one will work for you:

Thread Group
    HTTP Request
    //set-found-condition
    ${__setProperty(txtFound,FALSE,)}
    While Controller
    // invert value in condition - will be executed while txtFound == FALSE
    Condition = ${__BeanShell(!props.get("txtFound")}
    . . .
    [execute your test logic here]
    . . .
    YOUR HTTP Request
        Response Assertion
        // set your text assertion here
        // this will results in ${JMeterThread.last_sample_ok} = TRUE if text found
    IF Controller    --FOUND
    // if text found set separate variable or property - e.g. ${txtFound} - into TRUE
    Condition = ${JMeterThread.last_sample_ok}
        HTTP Request 
        //set-found-condition
        ${__setProperty(txtFound,TRUE,)}  // this will be inverted to FALSE in the next WHILE cycle's condition, WHILE cycle will be exited
    . . .

I think you may also easily use JSR / BSF / BeanShell PostProcessor attached to YOUR HTTP Request to set txtFound property into TRUE instead of cumbersome construction with IF.

等待圉鍢 2024-12-18 21:44:17

试试这个

Thread Group
xpath_Extractor or regex_extractor( variable = VAR_1 )
.. While controller( ${__javaScript("${VAR_1}" != "REQUIRED")} )
   .. HTTP request
Listener

Try this

Thread Group
xpath_Extractor or regex_extractor( variable = VAR_1 )
.. While controller( ${__javaScript("${VAR_1}" != "REQUIRED")} )
   .. HTTP request
Listener
丑疤怪 2024-12-18 21:44:17

http://jmeter.apache.org/usermanual/component_reference.html#While_Controller

WHILE 控制器将一直执行,直到某些内容设置为 FALSE。通过将条件设置为LAST,您将不会退出控制器,直到最后一个示例FAILS。如果样本包含您想要的文本,您是否使用断言使样本失败?

更简洁的方法可能是使用 beanshell 断言将值设置为 false。

http://jmeter.apache.org/usermanual/component_reference.html#While_Controller

The WHILE controller will execute until something is set to FALSE. By setting the condition as LAST, you won't exit the controller until the last sample FAILS. Are you using an assertion to FAIL the sample if it contains the text you want?

A cleaner way might be to a use a beanshell assertion to set a value to false.

幸福%小乖 2024-12-18 21:44:17

为了解决这个问题,我所做的就是创建一个正则表达式提取器并对其进行设置,以便它不可避免地失败并将我的变量设置为 FAIL。然后我将 while 循环设置为 ${__javaScript("${projLoad}" != "SUCCESS")}

在我的条件下,我创建了相同的正则表达式提取器再次失败,但将默认值更改为 < strong>成功

它可能不是最干净的,但效果很好

What I did to get around this issue was create a Regular Expression Extractor and set it up so that it would inevitably fail and set my variable to FAIL. Then I set my while loop to ${__javaScript("${projLoad}" != "SUCCESS")}

Under my conditions I created that same RegEx Extractor to fail again but changed the default value to SUCCESS

It's probably not the cleanest, but works like a charm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文