JMeter While Controller

◇◆丶佛笑我妖孽 提交于 2019-12-22 09:57:48

问题


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.


回答1:


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.




回答2:


Try this


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



回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/7886132/jmeter-while-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!