2013-10-01 29 views
0

解析陣列到url一個的每個值我有一種情況如何通過一個在JMeter的

用戶logsin

通過JSON路徑抽出我得到的所有的預約ID作爲數組

["75457052","75405285","75400251","75400246","75400252","75307496","75307497","75307498"] 

現在用戶需要導航像/預訂/ id來陣列

如果在響應從上述URL得到的,某些標準滿足中提到的所有ID(如實施例比如D estinationCount> 1),那麼它會返回該id並從循環中出來。

我需要這將符合條件的

回答

1

我不知道,如果JSON路徑抽出公開所有匹配的值作爲變量,如正則表達式做的第一個ID。你可以使用組合正則表達式提取器和foreach控制器,它看起來像下面這樣。

  • 線程組
    • HTTP取樣器將返回預約ID
      • Regex的後處理器,以匹配所有匹配的預約ID
    • 豆殼處理器初始化destinationCount = 0和初始化迭代我= 1
    • foreach控制器
      • ifcontroller(destinationCount < 1)
      • HTTP取樣與$ {reservation_id} _ $ {I}
        • BeanShell的處理器將所述destinationCount設置爲新的值

你可能想看看these屏幕轉換,看看究竟是如何實現正則表達式提取和foreach控制器。

+0

我已經用正則表達式和foreach做,但我一直在尋找如何才能從JSON路徑抽出通過輸出數組的每個值的ForEach控制器。 – asinha

0

我做的方法是如下

Navigate to reservations to get all the reservation ids 
Through regular expression extractor :- 
    Reference Name :- getreservationid 
    Regular expression:- "id": \"(.+?)\" 
    Match No :- -1 
    Template:- $1$ 

Then add foreach controller 
    input variable prefix :- getreservationid 
    output variable name :- reservationid 

Then add http sampler to go to each reservationid :- /reservation/${reservationid}/home 
Add json path extractor :- Name - numberOfLocations, JSON path  :- $.payload.destinationGuide.numberOfLocations 
    Then add if controller ${numberOfLocations} > '1' 
     Then add the http sampler as example go to the weather page of that id :- /reservation /${reservationid}/weather 
     //I need to go only once to that weather page and then come out of for each controller 
     then add BSF post processor -> beanshell (this is to remove all the variables so that it would come out from the foreach controller) 
     copy = new HashSet(vars.entrySet()); 
     for (Iterator iter = copy.iterator(); iter.hasNext();) { 
     e = iter.next(); 
     if (e.getKey().startsWith("getreservationid")) { 
      vars.remove(e.getKey()); 
     } 
    }