[英]How to get the JSON response from newman
您可以創建一個迷你項目並將 Newman 用作庫並使用腳本運行它。 這樣,您可以使用 node fs
模塊將響應寫入文件。
const newman = require('newman'),
fs = require('fs');
newman.run({
collection: '<Your Collection>'
}).on('request', function (error, data) {
if (error) {
console.error(error);
}
else {
fs.writeFile(`response.json`, data.response.stream.toString(), function (error) {
if (error) {
console.error(error);
}
});
}
});
該腳本使用 Newman .on('request')
事件,它將提取該信息。 如果您想要所有響應正文,您可能需要稍微修改一下,並且可能使用appendFileSync
來捕獲集合中請求的所有響應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.