我在我的ubuntu盒上安装了newman 3.9.3版本。希望从一个文件夹执行多个集合,但通过有线错误执行js文件
TypeError: newman.run不是一个函数。
这是我的执行脚本。任何帮助都将不胜感激。
#!/usr/bin/env node
var newman = require(process.env.NVM_BIN+'/newman');
var fs = require('fs');
fs.readdir('./collections', function (err, files) {
if (err) { throw err; }
files = files.filter(function (file) {
return (file.substr(-5) === '.json');
});
// now wer iterate on each file name and call newman.run using each file name
files.forEach(function (file) {
newman.run({
environment: require(`${__dirname}/live.postmane_environment.json`),
collection: require(`${__dirname}/collections/${file}`),
reporters: ['cli']
}, function (err) {
console.info(`${file}: ${err ? err.name : 'ok'}!`);
});
});
});以下是准确的错误。
/app/postman/execute:15 newman.run({ ^)
TypeError: newman.run不是在/app/postman/execute:15:16 at Array.forEach (原生) at /app/postman/execute:14:11 at FSReqWrap.oncomplete (fs.js:123:15)的函数。
发布于 2018-03-18 05:35:12
目前,我已经通过使用bash脚本来运行文件夹中可用的所有集合来解决这个问题。这已经完成了任务。但最初我不明白为什么"run“不适用于"newman”对象。
发布于 2018-05-30 11:14:48
我收到了相同的错误消息,并解决了安装nodejs包的问题:
npm install --save newman基本上,当您将bin作为引用时,nodejs不知道如何运行:
而不是:
var newman = require(process.env.NVM_BIN+'/newman');应:
var newman = require('newman');https://stackoverflow.com/questions/49117966
复制相似问题