2

每当我从命令行运行以下

newman run https://www.getpostman.com/collections/abcd1234

我得到显示失败和执行统计信息的输出。

但我正在寻找来自 URL 的完整 HTML 或 JSON 响应,以便在执行上述 Newman 查询后打印在终端上。我怎样才能做到这一点?

4

3 回答 3

0

您需要使用 Postman API。

所以你需要运行这样的东西

newman run https://api.getpostman.com/collections/myPostmanCollectionUid?apikey=myPostmanApiKey

(参见http://blog.getpostman.com/2018/06/21/newman-run-and-test-your-collections-from-the-command-line/)您可以在 Postman Cloud 中获取 ApiKey。您需要转到工作区 -> 集成 -> 浏览集成 -> Postman API 查看详细信息 -> 详细获取 API 密钥/现有 API 密钥

如果您还需要添加环境(如果您使用变量),您需要使用 -e 参数运行相同的命令 'newman run https://api.getpostman.com/collections/myPostmanCollectionUid?apikey=myPostmanApiKey -e dev_environment .json'

但是,如果您的环境也在云中呢?根据本文档https://www.getpostman.com/docs/v6/postman/collection_runs/command_line_integration_with_newman,您可以将 URL 作为值传递。所以你可以运行这样的东西

newman run https://api.getpostman.com/collections/myPostmanCollectionUid?apikey=myPostmanApiKey -e environments/{{environment_uid}}?apikey=myPostmanApiKey

它对我有用,希望这会有所帮助

于 2018-08-21T13:54:23.820 回答
0

您必须在请求中添加一些日志输出。

对于要查看响应输出的请求,在 Postman 测试选项卡中添加以下内容:

console.log(responseBody); // full response body

如果要记录特定部分,则必须将响应正文解析为 JSON 对象:

let response = JSON.parse(responseBody);
console.log(reponse.myprop); // part of the full response body

现在,如果您使用 newman 运行此集合,CLI 报告器也将打印控制台日志部分。

于 2017-03-06T09:03:45.973 回答
0

我正在使用 newman 进行 Web 服务和微服务测试。这对我来说很好。

summary.run.executions[0].response.text().toString()

完成事件后,您应该能够得到响应。

d 是从 Postman 导出的集合。

newman.run({
            collection: d,
            // reporters: 'cli',
            iterationCount: 1,
            timeoutRequest: 10000,
            timeoutScript: 5000,
            delayRequest: 0,
            insecure: false, 
        }).on('done', (err, summary) => {
            if (err || summary.error) {
                console.error('\ncollection run encountered an error.');
                reject(summary.error);
            }
            else {
                var xml = summary.run.executions[0].response.text().toString();
                console.log(xml)
            }
        })
    })
于 2018-12-24T17:25:15.950 回答