2012-02-20 235 views
0

我在Jmeter(2.5.1)中有測試用例。
我需要定義一個變量,然後在while循環改變它的價值,基本上是:因爲JMeter的加載用戶定義的變量,以在年初曾經內存JMeter循環變量

isQuest = true; 
while(${isQuest}){ 
    Http Sampler 
     Reg Exp Extractor -> set the isQuest based on the result 
} 

,它不會讓我分配另一個值存儲器中的變量。

克服這個問題的最好方法是什麼?

+0

[得到了答案?](http://stackoverflow.com/faq#howtoask) – 2012-09-08 11:02:13

回答

1

您可以使用JMeter的屬性而不是變量,通過jmeter functions或BeanShell的代碼訪問:

${__P(whileCondition,)} 
${__setProperty(whileCondition,TRUE,)} 
${__BeanShell(props.get("whileCondition")} 
${__BeanShell(props.set("whileCondition")} 

您可以嘗試使用類似如下結構:

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

我想你也可以輕鬆使用附加到的BSF或BeanShell PostProcessor您的HTTP請求將txtFound屬性設置爲TRUE,而不是使用IF進行繁瑣的構建。

0

不,您可以在運行時爲用戶定義的變量賦值。如果你使用BeanShell預處理器,vars.put("variablename", "variablevalue");