如何获取 Postman Environment 和 Postman Globals URL 以传递给 Newman?

Yur*_*riK 3 postman newman

Newman 帮助指定集合、环境和全局变量可以作为路径或 URL 传递。我可以看到如何从 Postman 获取收藏 URL(通过转到“共享”>“收藏链接”)。
如何在 Postman 中获取 Environment 和 Globals 的 URL,以便将它们传递给 newman?

小智 6

将 Newman 与 Postman Pro API 结合使用:

  1. 生成 API 密钥
  2. 从以下位置获取您的收藏列表:
    https://api.getpostman.com/collections?apikey=$apiKey
    
    Run Code Online (Sandbox Code Playgroud)
  3. 通过其 UID 获取集合链接:
    https://api.getpostman.com/collections/$uid?apikey=$apiKey
    
    Run Code Online (Sandbox Code Playgroud)
  4. 从以下位置获取环境 URI:
    https://api.getpostman.com/environments?apikey=$apiKey
    
    Run Code Online (Sandbox Code Playgroud)
  5. 使用在步骤 3 和 4 中获取的集合和环境 URI,按如下方式运行集合:
    newman run "https://api.getpostman.com/collections/$uid?apikey=$apiKey" \
        --environment "https://api.getpostman.com/environments/$uid?apikey=$apiKey"
    
    Run Code Online (Sandbox Code Playgroud)

链接到纽曼包


Meg*_*n D -4

在命令行中,使用 newman命令行选项

-e <source>, --environment <source>
Specify an environment file path or URL. Environments provide a set 
of variables that one can use within collections. Read More

-g <source>, --globals <source>
Specify file path or URL for global variables. Global variables are 
similar to environment variables but has a lower precedence and can 
be overridden by environment variables having same name.
Run Code Online (Sandbox Code Playgroud)

如果您使用 newman 作为Node JS 模块,请提供环境和全局作为 newman.run() 的选项:

newman.run({environment: <source>, globals: <source>}, callback)
Run Code Online (Sandbox Code Playgroud)

  • 一旦您获得了环境或全局变量的 URL,这一切都很好。实际的问题是从哪里获取这些 URL!我将解释一下:在 Postman Pro 中,您可以共享集合,而在 Collection Link 中,有一个可以传递给 newman 的 URL。没有环境链接或全局链接(甚至共享)选项。那么如何获取Postman Pro中Environment和Globals的URL呢? (3认同)