artillery.io JSON值捕获不起作用

时间:2017-10-25 08:40:20

标签: json jsonpath

使用Artillery.io 1.6.0-10,我调用一个返回JSON的api并尝试捕获其中一个值供以后在流中使用,但捕获似乎不起作用。这是简化的代码:

get_ddg.yml

config:
  target: "https://api.duckduckgo.com"
  phases:
    - duration: 3
      arrivalCount: 1
scenarios:
  - name: "Get search"
    flow:
      - get:
          url: "/?q=DuckDuckGo&format=json"
          capture:
            json: "$.Abstract"
            as: "abstract"
      - log: "Abstract: {{ $abstract }}"

当我运行炮兵时,值为空:

$ artillery run get_ddg.yml
Started phase 0, duration: 3s @ 10:28:34(+0200) 2017-10-25
⠋ Abstract:   <----- EMPTY! NO VALUE FOR $abstract
Report @ 10:28:37(+0200) 2017-10-25
Scenarios launched:  1
Scenarios completed: 1
Requests completed:  1
Concurrent users:    1
RPS sent: 2.08
Request latency:
  min: 311.9
  max: 311.9
  median: 311.9
  p95: NaN
  p99: NaN
Scenario duration:
  min: 349.5
  max: 349.5
  median: 349.5
  p95: NaN
  p99: NaN
Codes:
  200: 1

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

找到解决方案。问题是捕获后如何读取变量。调用变量的正确方法是不使用&#39; $&#39;:

- log: "Abstract: {{ abstract }}"