How to get Postman Environment and Postman Globals URLs for passing to Newman?

瘦欲@ 提交于 2021-01-28 06:13:59

问题


Newman help specifies that collection, environment and globals can be passed as a path or as a URL. I can see how to get a collection URL from Postman (by going to Share > Collection Link).
How can I get the URLs to Environment and Globals in Postman, so I could pass them to newman?


回答1:


Using Newman with the Postman Pro API:

  1. Generate an API key
  2. Fetch a list of your collections from:
    https://api.getpostman.com/collections?apikey=$apiKey
    
  3. Get the collection link via its UID:
    https://api.getpostman.com/collections/$uid?apikey=$apiKey
    
  4. Obtain the environment URI from:
    https://api.getpostman.com/environments?apikey=$apiKey
    
  5. Using the collection and environment URIs acquired in steps 3 and 4, run the collection as follows:
    newman run "https://api.getpostman.com/collections/$uid?apikey=$apiKey" \
        --environment "https://api.getpostman.com/environments/$uid?apikey=$apiKey"
    

Link to Newman package




回答2:


Using the Postman desktop app please try the following steps -

  1. View your collection in Postman
  2. From the collection details view (press the arrow next to the collection name) and select View in Web.
  3. In the Postman web view, next to the Postman logo on the right, there is a drop-down.
  4. From the drop-down select the Workspace where your test collection is in.
  5. On the Collection list page, you will see Environments as a tab next to Collections.
  6. Select the Environments tab, then select the specific environment you want.
  7. The URL on this page is the Environment's URL you can use for Postman.



回答3:


via Postman, I exported my environment as a json file, and then hosted that file on a webserver.




回答4:


I didn't get that how to get Postman Globals URLs for passing to Newman? I am only able to get the collection and Environment URL.




回答5:


From the command line, use the newman command line options:

-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.

If you use newman as a Node JS module, provide environment and global as options to newman.run():

newman.run({environment: <source>, globals: <source>}, callback)


来源:https://stackoverflow.com/questions/46460302/how-to-get-postman-environment-and-postman-globals-urls-for-passing-to-newman

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!