2017-10-21 68 views
1

我想創建一個執行循環的腳本,並用Http結果填充數組。 預期的結果是帶有密碼的數組,以及循環的大小(在示例3中)。 問題是,在循環的每次迭代中,我都不熟悉在循環的第一次迭代中創建的數組。 有人可以請建議如何在Jmeter中的循環內填充數組? 或者如何解決這個問題?任何示例都會很棒在Jmeter + Groovy中處理循環和數組 - 響應代碼500

res_g1 - 是我想要輸入到數組中每個位置的值,即指定密碼。 密碼 - 是,我想感覺與數據 循環計數器陣列 - 計算循環1,2,3

def loop_counter = ${__counter(TRUE)}; 
def results = vars.get('res_g1') 
if (loop_counter == 1) 
{ 
    def Password = new String[3]; 
    System.out.println("Entered the loop"); 
} 

Password[loop_counter -1] = vars.get('res_g1'); 
System.out.println("loop number is : " + loop_counter + " Password is" + results); 

enter image description here

enter image description here

enter image description here

的迭代

enter image description here

enter image description here

+0

不清楚你試圖做什麼。錯誤'沒有這樣的屬性密碼類Scrit ...'意味着你試圖訪問變量,它沒有聲明。 'def密碼'在'if(loop_counter == 1){...}'後面消失# – daggett

+0

你好,對答案有任何反饋?如果確定,它應該被標記爲「確定」並且被提升,以便其他人可以使用它。謝謝 –

回答

0

這裏是如何做到這一點:

使用Counter元素內循環:

enter image description here

然後使用這個腳本:

enter image description here

要注意:

被檢查
  • 緩存編譯腳本演出
  • 陣列的存儲我要填寫爲使用vars.putObject(...)
  • 的vars.getObject一個變量()把它找回來
  • 使用SLF4J的Logger.info代替System.out.println的日誌記錄