Как передать значение переменной среды Postman в сценарий nodejs, выполняющий Newman? - PullRequest
0 голосов
/ 24 февраля 2020

Пример: при выполнении newman в командной строке пользователь должен сделать:

newman run CollectionName.json --env-var baseurl="myhost/url" --env-var user="admin" --env-var password="admin123"

Как можно передать такой параметр, как --env-var user = "admin", при использовании такой сценарий?

// myNodeScript.js
const newman = require('newman');
const fs = require('fs');
xml2js = require('xml2js');
newman.run({
  collection: require("./PostmanCollections/CollectionName.json"),
  folder: "Sanity",
  globals: require("./postmanVariables/QAWorkspace.postman_globals.json"), 
  environment: require("./postmanVariables/A1Env.postman_environment.json"),
  exportEnvironment: "myEnv.json",
  exportGlobals: "myGlobals.json",
  reporters: "cli",
}).on('start', function (error, summary) { // ...

1 Ответ

0 голосов
/ 24 февраля 2020

В вашем postman_environment.json вы можете указать следующее:

{
  "id": "a14232bb-48d3-3494-7e6f-f4f34e6331a4",
  "name": "testEnv",
  "values": [
    {
      "enabled": true,
      "key": "baseurl",
      "value": "myhost/url",
      "type": "text"
    },
    {
      "enabled": true,
      "key": "user",
      "value": "admin",
      "type": "text"
    }
  ],
  "timestamp": 1504039485918,
  "_postman_variable_scope": "environment",
  "_postman_exported_at": "2017-08-29T20:44:53.396Z",
  "_postman_exported_using": "Postman/5.1.3"
}
...