0

我有一个场景

用户登录

通过json路径提取器,我将所有预订ID作为一个数组

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

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

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

我需要符合条件的第一个 id

4

2 回答 2

1

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

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

您可能想查看这些屏幕截图,以确切了解 regex 提取器和 foreach 控制器是如何实现的。

于 2013-10-02T04:21:19.377 回答
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());
       }
     }
于 2013-10-02T09:56:56.000 回答