node.js - 在 'capture' 上获得的 Artillery.io 值在 'expect' 上不可用

标签 node.js testing automated-tests node-modules artillery

我是 artillery.io 的新手,遇到了问题。 我想从 JSON 响应中获取一个值并在“expect”子句中检查它,所以我这样做是这样的:

config:
  target: 'https://api.duckduckgo.com'
  plugins:
      expect: {}
  phases:
    - duration: 1
      arrivalRate: 1
scenarios:
   - flow:
      - get:
          url: "/?q=cao&format=json"
          capture:
            - json: $RelatedTopics[0].FirstURL
              as: url
          expect:
            - statusCode: 200
            - equals:
              - "{{ url }}"
              - "https://duckduckgo.com/209/Cao_Wei"
      - log: "url is {{ url }}"

然后我就这样调用火炮:

artillery run duck.yml

然后我得到这样的东西:

User variables:
     target : https://api.duckduckgo.com
     $environment : undefined
     $uuid : 0774da00-b6e6-415c-bd28-0ff4bedd07ec
  not ok equals , https://duckduckgo.com/209/Cao_Wei 
  expected: all values to be equal
       got: , https://duckduckgo.com/209/Cao_Wei
  Request params:
    https://api.duckduckgo.com/?q=cao&format=json
    ""

我省略了其余的输出,因为它太大了。 当它说“not ok equals , https://duckduckgo.com/209/Cao_Wei”时,我觉得我的 url 变量未定义。

在“$RelatedTopics[0].FirstURL”这样的引号上使用 JSONPath 会产生同样的问题。

我像这样安装了 expect ( https://artillery.io/docs/plugin-expectations-assertions/) 插件:

npm install -g artillery-plugin-expect

拜托,我在这里错过了什么?

最佳答案

如果您升级到插件的最新版本 (1.2.1),该问题应该会消失,早期版本在涉及捕获变量的 equals 比较中存在错误(引用:https://github.com/artilleryio/artillery-plugin-expect/pull/4)

关于node.js - 在 'capture' 上获得的 Artillery.io 值在 'expect' 上不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53584995/

相关文章:

node.js - 从外部模块加载文件而不导出

javascript - 如何将 Replacer 函数与 JSON Stringify 结合使用?

go - 模拟 bufio.Scanner 输入

testing - 通过桌面应用程序加载测试 Web 服务器

r - 我应该把 testthat 自动化测试的数据放在哪里?

python - RobotFramework 中两个变量的总和

Node.js:是否有关于 process.env 变量的文档

node.js - 处理 gulp 代码中的 Promise 拒绝

java - 如何为在 run() 中具有无限循环的 Runnable java 类编写 UT?

rest - testcafe是否支持rest api的测试