JMeter 单独使用变量数组值

JMeter use variable array values individually

我有点难以利用使用 Json 提取器创建的变量,我已经从响应中提取了所有 ID,并希望在线程中单独循环访问它们。

线程 1 将使用 id_1,线程 2 将使用 id_2 等

我试过使用 ForEach 控制器,但它会为每个线程循环整个集合。

测试运行如下:

  1. 生成访问令牌
  2. 获取参数 - 在此处提取 ID 列表。
  3. 更新参数 - 在此处为每个线程单独传递 ID。

有办法实现吗?

您将无法执行此操作,因为根据 documentation:

Properties are not the same as variables. Variables are local to a thread; properties are common to all threads, and need to be referenced using the __P or __property function.

因此,如果您想使用一个线程执行提取,然后使用多个线程执行所有操作,您可以使用以下 Groovy code 代码段将所有以 id_ 开头的变量转换为 JMeter 属性:

vars.entrySet().each { variable ->
    if (variable.getKey().startsWith('id_')) {
        props.put(variable.getKey(), variable.getValue())
    }
}

然后您将能够使用 __P() function 访问属性,例如:

${__P(id_${__threadNum},)}