简体   繁体   English

如何在 CI 环境中运行 postman 的 newman?

[英]How do I run postman's newman in CI environment?

I'd like to run newman on my CI environment (solano-ci).我想在我的 CI 环境 (solano-ci) 上运行newman

newman is a tool that runs through requests in your postman collection. newman是一个工具,它运行您的邮递员集合中的请求。

I have a newman script in my package.json , and I also have a npm start script that starts the server at localhost:3000 .我的package.json有一个newman脚本,我还有一个npm start脚本,它在localhost:3000处启动服务器。

newman is already configured with environment variables to test endpoints on port localhost:3000 . newman已经配置了环境变量来测试端口localhost:3000上的端点。

The issue is I need one script that starts the server ( npm start ) and then runs npm run newman .问题是我需要一个脚本来启动服务器( npm start )然后运行npm run newman But there's a delay between when the server is available and when newman runs it's tests.但是在服务器可用和newman运行它的测试之间存在延迟。 If newman runs before the server is available it results in an error for each test.如果newman在服务器可用之前运行,它会导致每次测试出错。

Error: connect ECONNREFUSED 127.0.0.1:3000

Right now here's what I tried using run-p which works at starting two processes in parallel.现在这是我尝试使用run-p尝试并行启动两个进程的方法。 Then I have to use sleep and set an arbitrary number of time the wait to ensure that the server is ready.然后我必须使用sleep并设置任意次数的等待以确保服务器准备就绪。

"newman": "newman -c ./postman/api.postman_collection.json -e ./postman/local.postman_environment.json",
"newman-sleep": "sleep 10 && npm run newman",
"newman-server": "run-p start newman-sleep"

You can use wait-on package.您可以使用等待包。

npm install --save-dev wait-on

Then,然后,

"newman-sleep": "wait-on http://localhost:3000 && npm run newman"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 node 运行 newman (Postman) 集合时如何处理异步调用? - How do I handle asynchronous calls when running newman (Postman) collections with node? 如何在Travis CI中访问环境变量 - How do I access environment variables in Travis CI 邮递员(JavaScript)-如何根据JSON数组中的对象数创建环境变量? - Postman (JavaScript) - How do I create environment variables based on how many objects are in a JSON array? 如何阻止 Postman 纽曼消费 JavaScript Memory - How to Stop Postman Newman From Consuming JavaScript Memory 如何在类似环境的控制台中运行JavaScript? - How do I run JavaScript in a console like environment? 如何在 JavaScript 中使用 Netlify 的环境变量? - How do I use Netlify's environment variables in JavaScript? 如何将 Netlify 的环境变量与 vanilla JavaScript 一起使用? - How do I use Netlify's environment variables with vanilla JavaScript? Marvel API 和 Insomnia(或 Postman):如何传递所需的哈希值? - Marvel API and Insomnia (or Postman): how do I pass the hash value that's required? 在 Newman 脚本中访问环境变量 - Accessing environment variable in Newman script 如何将令牌值从一个集合传递到 POSTMAN 中的另一个集合 - 自动化 | 新人 - How to pass token value from one collection to another collection in POSTMAN - AUTOMATION | NEWMAN
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM