【问题标题】:Newman + Postmant Specify a single environment variable via command lineNewman + Postman 通过命令行指定单个环境变量
【发布时间】:2017-10-10 23:37:39
【问题描述】:

我正在使用 newman 和 postman 运行一套 postman 请求和相关的测试脚本。

我有一个环境变量,它是一条我无法存储在磁盘上的敏感信息(因此我无法在 JSON 测试文件中声明它)。我需要有一些简单的方法将其传递到测试中。

我想在运行测试时在命令行上为环境变量分配一个值作为参数。

我像这样运行测试:

newman run c:\path\to\test.json

我想做这样的事情:

newman run c:\path\to\test.json passwordEnvVariable=mypassword

这样的事情可能吗?

【问题讨论】:

    标签: javascript json http testing postman


    【解决方案1】:

    环境变量使用:

    newman run c:\path\to\test.json --env-var passwordEnvVariable=mypassword
    

    根据纽曼文档: https://www.npmjs.com/package/newman

    【讨论】:

      【解决方案2】:

      您可以使用newman run collection.json --global-var "<global-variable-name>=<global-variable-value>"

      【讨论】:

      • 请解释你的答案。这将对未来的用户有所帮助。
      【解决方案3】:

      试试这个键:

      --global-var <value>            Allows the specification of global variables via the command line, in a key=value format
      

      【讨论】:

        【解决方案4】:

        根据newman的document,没有这个选项。目前,传递环境变量的唯一方法是传递文件路径或 URL。

        但是,@michaelajr 在 8 天前(5 月 4 日)提出了功能请求,这正是您想要的:Pass environment variables on the command line。由于 newman 团队已经承认了这个功能,并且没有在线程中发布解决方法,因此也不太可能找到解决方法。

        希望纽曼尽快添加此功能。

        【讨论】:

          猜你喜欢
          • 2019-01-23
          • 1970-01-01
          • 2019-08-25
          • 2015-12-30
          • 2018-02-08
          • 1970-01-01
          • 2022-08-16
          • 2016-09-24
          • 2015-10-12
          相关资源
          最近更新 更多