2011-10-25 118 views
3

我已經搜遍瘋狂的解決方案,我的問題在整個網絡,但沒有存在。我的問題是,我必須檢查是否在HTTP請求中獲得特定文本,這是在while循環中,如果我這樣做,那麼我應該離開循環並繼續使用線程,或者在文本不存在的情況下完全停止線程。我已經將它設置如下:JMeter雖然控制器

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

我用的,而控制器LAST設置爲false文本HTTP響應,並沒有工作。

回答

2

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

的WHILE控制器將執行直到一些被設置爲FALSE。通過將條件設置爲LAST,您將不會退出控制器,直到最後一個樣本失敗。如果包含您想要的文本,您是否使用斷言來使樣本失敗?

更簡潔的方法可能是使用beanshell斷言來將值設置爲false。

+0

是的,我使用的響應斷言失敗樣本,如果文本不存在。 – Jurij

4

希望下面的人會爲你工作:

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

我想你也可以很容易地使用連接到您的HTTP請求JSR/BSF/BeanShell PostProcessortxtFound屬性設置爲TRUE,而不是笨重的建設與IF的。

+0

感謝這個想法......使用BSF PreProcessor作爲While Controller的子程序允許我通過While Controller正確評估條件。 – pulkitsinghal

3

試試這個

 

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

我所做的來解決這個問題是創建一個正則表達式提取並進行設置,使其將不可避免地失敗,並設置我的變量失敗。然後,我把我的while循環$ {__使用Javascript(「$ {projLoad}」!=「SUCCESS」)}

在我的條件我創造出相同的正則表達式提取再次失敗,但改變了默認值SUCCESS

它可能不是最乾淨的,但就像一個魅力

相關問題