2017-06-21 54 views
0

豆殼後處理器代碼:如何在beanshell後處理器中設置Jmeter Loop Controller中的動態值?

int totalElements= Integer.parseInt(vars.get("totalElements")); 
vars.put("totalElements", String.valueOf(totalElements)); 

在迴路控制器,我用以下這些,但不能得到這個值。

${__javaScript(parseInt(${totalElements})}; 
${__javaScript(parseInt("${totalElements}"))}; 
${__V(totalElements)}; 
${totalElements}; 

回答

0

嘗試變量名沒有分號:

enter image description here

的另一個問題是,如果由於某種原因變量totalElements沒有定義,聲明vars.get("totalElements")將返回null和解析Integer.parseInt(null)會導致一個例外,這將導致採樣器的失敗。如果這是一個預期的行爲,罰款,但如果沒有,你可以這樣做:

String value = vars.get("totalElements"); 
int totalElements = (value != null) ? Integer.parseInt(value) : 0; 
vars.put("totalElements", String.valueOf(totalElements)); 

所以,如果變量不能被檢索,totalElements設置爲0,因此循環將無法運行。但採樣器也不會失敗。

0

我得到了這個問題的解決方案。曾在按照以下腳本:

int totalElements= Integer.parseInt(vars.get("totalElements")); 
vars.put("totalElements", String.valueOf(totalElements)); 

然後我在迴路控制器使用${__javaScript("${totalElements}")}和工作正常。

相關問題