如何在jmeter中逐个将数组的每个值解析为url

时间:2013-10-01 14:34:49

标签: json jmeter

我有一个场景

用户登录

通过json路径提取器我将所有预留ID作为数组

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

现在用户需要像/ reservation / id一样导航到数组中提到的所有ID

如果在响应中从上面的url获得某些条件符合(例如说destinationCount> 1)那么它将返回该id并退出循环。

我需要第一个符合标准的ID

2 个答案:

答案 0 :(得分:1)

我不确定JSON路径提取器是否将所有匹配的值公开为变量,就像regex一样。您可以使用组合正则表达式提取器和foreach控制器,它们看起来如下所示。

  • 线程组
    • HTTP Sampler将返回预订ID
      • 正则表达式后处理器匹配所有匹配的预订ID
    • Bean shell处理器初始化destinationCount = 0并初始化迭代器i = 1
    • foreach控制器
      • ifcontroller(destinationCount< 1)
      • 带有$ {reservation_id}的HTTP采样器_ $ {i}
        • Beanshell处理器将destinationCount设置为新值

您可能需要查看these屏幕强制转换,以确切了解正则表达式提取器和foreach控制器的实现方式。

答案 1 :(得分: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());
       }
     }