{"action":"created","issue":{"url":"https://api.github.com/repos/postmanlabs/newman/issues/626","repository_url":"https://api.github.com/repos/postmanlabs/newman","labels_url":"https://api.github.com/repos/postmanlabs/newman/issues/626/labels{/name}","comments_url":"https://api.github.com/repos/postmanlabs/newman/issues/626/comments","events_url":"https://api.github.com/repos/postmanlabs/newman/issues/626/events","html_url":"https://github.com/postmanlabs/newman/issues/626","id":178431303,"number":626,"title":"newman.run() not pulling in the environment option","user":{"login":"danonorato","id":338000,"avatar_url":"https://avatars0.githubusercontent.com/u/338000?v=4","gravatar_id":"","url":"https://api.github.com/users/danonorato","html_url":"https://github.com/danonorato","followers_url":"https://api.github.com/users/danonorato/followers","following_url":"https://api.github.com/users/danonorato/following{/other_user}","gists_url":"https://api.github.com/users/danonorato/gists{/gist_id}","starred_url":"https://api.github.com/users/danonorato/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danonorato/subscriptions","organizations_url":"https://api.github.com/users/danonorato/orgs","repos_url":"https://api.github.com/users/danonorato/repos","events_url":"https://api.github.com/users/danonorato/events{/privacy}","received_events_url":"https://api.github.com/users/danonorato/received_events","type":"User","site_admin":false},"labels":[{"id":84268807,"url":"https://api.github.com/repos/postmanlabs/newman/labels/bug","name":"bug","color":"fc2929","default":true},{"id":345576044,"url":"https://api.github.com/repos/postmanlabs/newman/labels/needs-investigation","name":"needs-investigation","color":"c7def8","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":13,"created_at":"2016-09-21T18:49:06Z","updated_at":"2017-08-03T08:13:02Z","closed_at":"2016-09-22T09:54:30Z","body":"It appears newman.run() parses a exported  Postman environment JSON file w/out error but fails to use the environment at run-time.\n\nhere is the console output from a very simple test.js file as well as running the same collection and environment via newman CLI(which works as expected).  I've attached the newman_pos.js file along with the environment and collection files.  \n\nThe newman_poc.js script prints out the summary.collection.  you can see the environment is [].  You will also notice in the console output the InvalidURL error as the {{url}} env var is not being pulled in from the environment.\n\n```/src/postman danonorato $ node newman_poc.js\nrunning a collection...\nRunning 1 request(s) and 1 iteration(s)\nnewman\n\ngoogle_test\n\n→ http://{{url}}\n  GET http://{{url}} [errored]\n  2⠄ ReferenceError in test-script\ncollection run completed.\nPostmanCollection {\n  description: PostmanPropertyDescription { content: '', type: 'text/plain' },\n  _: { postman_id: 'e61faac5-348d-4550-da1c-de37af2870b3' },\n  id: 'e61faac5-348d-4550-da1c-de37af2870b3',\n  name: 'google_test',\n  disabled: undefined,\n  items:\n   PostmanPropertyList {\n     members: [ [Object] ],\n     reference: { 'd4148304-7da8-4c04-b263-7d9545f1b353': [Object] },\n     Type: [Function],\n     _postman_propertyIndexKey: 'id',\n     _postman_propertyIndexCaseInsensitive: false },\n  events:\n   PostmanEventList {\n     members: [],\n     reference: {},\n     Type: { [Function: PostmanEvent] _postman_propertyName: 'Event' },\n     _postman_propertyIndexKey: 'id',\n     _postman_propertyIndexCaseInsensitive: false },\n  variables:\n   PostmanVariableList {\n     _environments: [],\n     members: [],\n     reference: {},\n     Type:\n      { [Function: PostmanVariable]\n        _postman_propertyName: 'Variable',\n        types: [Object],\n        isVariable: [Function] },\n     _postman_propertyIndexKey: 'id',\n     _postman_propertyIndexCaseInsensitive: false },\n  version: undefined }\n\n┌─────────────────────────┬──────────┬──────────┐\n│                         │ executed │   failed │\n├─────────────────────────┼──────────┼──────────┤\n│              iterations │        1 │        0 │\n├─────────────────────────┼──────────┼──────────┤\n│                requests │        1 │        1 │\n├─────────────────────────┼──────────┼──────────┤\n│            test-scripts │        1 │        1 │\n├─────────────────────────┼──────────┼──────────┤\n│      prerequest-scripts │        0 │        0 │\n├─────────────────────────┼──────────┼──────────┤\n│              assertions │        0 │        0 │\n├─────────────────────────┴──────────┴──────────┤\n│ total run duration: 518ms                     │\n├───────────────────────────────────────────────┤\n│ total data received: 0B (approx)              │\n├───────────────────────────────────────────────┤\n│ average response time: 0ms                    │\n└───────────────────────────────────────────────┘\n\n  #  failure                         detail\n\n 1⠄  Error                           Invalid URI \"http:///%7B%7Burl%7D%7D\"\n                                     at request\n                                     inside \"http://{{url}}\" of \"google_test\"\n\n 2⠄  ReferenceError                  responseCode is not defined\n                                     at test-script:5:31\n                                     inside \"http://{{url}}\" of \"google_test\"```\n\nNow from the command line\n```~/src/postman danonorato $ newman run -e google.postman_environment.json google_test.postman_collection.json\nnewman\n\ngoogle_test\n\n→ http://{{url}}\n  GET http://www.google.com [200 OK, 5.31KB, 131ms]\n  ✓  Status code is 200\n\n┌─────────────────────────┬──────────┬──────────┐\n│                         │ executed │   failed │\n├─────────────────────────┼──────────┼──────────┤\n│              iterations │        1 │        0 │\n├─────────────────────────┼──────────┼──────────┤\n│                requests │        1 │        0 │\n├─────────────────────────┼──────────┼──────────┤\n│            test-scripts │        1 │        0 │\n├─────────────────────────┼──────────┼──────────┤\n│      prerequest-scripts │        0 │        0 │\n├─────────────────────────┼──────────┼──────────┤\n│              assertions │        1 │        0 │\n├─────────────────────────┴──────────┴──────────┤\n│ total run duration: 691ms                     │\n├───────────────────────────────────────────────┤\n│ total data received: 4.7KB (approx)           │\n├───────────────────────────────────────────────┤\n│ average response time: 131ms                  │\n└───────────────────────────────────────────────┘```\n\nI had to change the extensions to txt to attach.\nnewman_poc.txt  -> newman_poc.js\ngoogle.postman_environment.txt -> google.postman_environment.json\ngoogle_test.postman_collection.txt -> google_test.postman_collection.json\n\n[newman_poc.txt](https://github.com/postmanlabs/newman/files/485794/newman_poc.txt)\n[google.postman_environment.txt](https://github.com/postmanlabs/newman/files/485793/google.postman_environment.txt)\n[google_test.postman_collection.txt](https://github.com/postmanlabs/newman/files/485792/google_test.postman_collection.txt)\n\n -> google_test.postman_collection.json\n"},"comment":{"url":"https://api.github.com/repos/postmanlabs/newman/issues/comments/319900381","html_url":"https://github.com/postmanlabs/newman/issues/626#issuecomment-319900381","issue_url":"https://api.github.com/repos/postmanlabs/newman/issues/626","id":319900381,"user":{"login":"kunagpal","id":7289840,"avatar_url":"https://avatars3.githubusercontent.com/u/7289840?v=4","gravatar_id":"","url":"https://api.github.com/users/kunagpal","html_url":"https://github.com/kunagpal","followers_url":"https://api.github.com/users/kunagpal/followers","following_url":"https://api.github.com/users/kunagpal/following{/other_user}","gists_url":"https://api.github.com/users/kunagpal/gists{/gist_id}","starred_url":"https://api.github.com/users/kunagpal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kunagpal/subscriptions","organizations_url":"https://api.github.com/users/kunagpal/orgs","repos_url":"https://api.github.com/users/kunagpal/repos","events_url":"https://api.github.com/users/kunagpal/events{/privacy}","received_events_url":"https://api.github.com/users/kunagpal/received_events","type":"User","site_admin":false},"created_at":"2017-08-03T08:13:02Z","updated_at":"2017-08-03T08:13:02Z","body":"@SeekerResource It looks like you're trying to reference the variable called `at_e_hostname`, which is missing. Could you do the following to confirm that you're using the environment correctly?\r\n\r\n1. Update Newman to v3.8.0.\r\n2. Ensure that the `newman run ...` command includes an option to load the environment file, like so: `newman run collection.json -e env.json`. If you're using Newman as a library, ensure that the options object passed to `newman.run` contains a valid environment option, like so:\r\n```js\r\nnewman.run({\r\n    collection: <>, // this can be a relative path to the collection, or the collection JSON itself\r\n    environment: <> // similar to the above\r\n}, function (err, summary) {\r\n    // Do something with the err and summary here\r\n});\r\n```\r\n3. In the test/pre-request scripts for the erroring request, please add `console.log(environment);` and verify that the resultant value is indeed valid.\r\n\r\nIf all of the above conditions are satisfied and you're still experiencing issues with variable resolution, please open a new issue at https://github.com/postmanlabs/newman/issues/new and we'll be more than happy to help you out. Thanks! 😄 "}}
{"actor":{"display_login":"kunagpal"}}