请求的响应在纽曼的 json 报告中显示为空
Response of Requests made shown as empty in json report of newman
在 运行 使用 newman 和 json 记者收集后,生成 json 文件。
但对于响应部分,它是 [] 即空的,同时它具有不同的具有适当值的响应相关属性(例如,对于 responseTime、responseSize 等)。
那么我怎样才能得到这个 json 记者的回复 body/data。
根据我的实际需求,我需要在 json 或 excel/csv 格式文件中记录每个请求的响应。
虽然我无法直接解决这个问题,但我使用 Newman 作为 javascript 库并将请求和响应记录在单独的文本文件中。
生成的文件将具有请求文件的文件名,如request1、request2等;类似的行为将用于响应文件及其每次执行的名称。
下面是上述解决方案的代码:
const newman = require('newman'),
fs = require('fs');
var rq = 1;
var rs = 1;
newman.run({
collection: require('./ABC.postman_collection.json'),
environment: require('./XYZ.postman_environment.json'),
iterationData: './DataSet.csv',
reporters: 'cli'
}).on('beforeRequest', function (error, args) {
if (error) {
console.error(error);
} else {
fs.writeFile('request' + rq++ + '.txt', args.request.body.raw, function (error) {
if (error) {
console.error(error);
}
});
}
}).on('request', function (error, args) {
if (error) {
console.error(error);
}
else {
fs.writeFile('response' + rs++ + '.txt', args.response.stream, function (error) {
if (error) {
console.error(error);
}
});
}
});
在 运行 使用 newman 和 json 记者收集后,生成 json 文件。
但对于响应部分,它是 [] 即空的,同时它具有不同的具有适当值的响应相关属性(例如,对于 responseTime、responseSize 等)。
那么我怎样才能得到这个 json 记者的回复 body/data。
根据我的实际需求,我需要在 json 或 excel/csv 格式文件中记录每个请求的响应。
虽然我无法直接解决这个问题,但我使用 Newman 作为 javascript 库并将请求和响应记录在单独的文本文件中。
生成的文件将具有请求文件的文件名,如request1、request2等;类似的行为将用于响应文件及其每次执行的名称。
下面是上述解决方案的代码:
const newman = require('newman'),
fs = require('fs');
var rq = 1;
var rs = 1;
newman.run({
collection: require('./ABC.postman_collection.json'),
environment: require('./XYZ.postman_environment.json'),
iterationData: './DataSet.csv',
reporters: 'cli'
}).on('beforeRequest', function (error, args) {
if (error) {
console.error(error);
} else {
fs.writeFile('request' + rq++ + '.txt', args.request.body.raw, function (error) {
if (error) {
console.error(error);
}
});
}
}).on('request', function (error, args) {
if (error) {
console.error(error);
}
else {
fs.writeFile('response' + rs++ + '.txt', args.response.stream, function (error) {
if (error) {
console.error(error);
}
});
}
});