Created
February 7, 2024 10:29
-
-
Save aryalakshmi/4040e68a9b7a6253d467c846ccba9c45 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const newman = require('newman'); // require newman in your project | |
const fs = require('fs'); | |
let logs = []; | |
// call newman.run to pass `options` object and wait for callback | |
newman.run({ | |
collection: require('./mock2.postman_collection.json'), | |
reporters: ['cli','json' , 'htmlextra'], | |
environment: 'WebGUI_URL.postman_environment.json', | |
reporter: { | |
htmlextra: { | |
export: './report.html', | |
// template: './template.hbs' | |
logs: true, | |
// showOnlyFails: true, | |
noSyntaxHighlighting: true, | |
testPaging: true, | |
// browserTitle: "My Newman report", | |
title: "Sports Data Odds", | |
// titleSize: 4, | |
omitHeaders: true, | |
// skipHeaders: "Authorization", | |
// omitRequestBodies: true, | |
// omitResponseBodies: true, | |
// hideRequestBody: ["Login"], | |
// hideResponseBody: ["Auth Request"], | |
// showEnvironmentData: true, | |
// skipEnvironmentVars: ["API_KEY"], | |
// showGlobalData: true, | |
// skipGlobalVars: ["API_TOKEN"], | |
// skipSensitiveData: true, | |
// showMarkdownLinks: true, | |
// showFolderDescription: true, | |
// timezone: "Australia/Sydney", | |
// skipFolders: "folder name with space,folderWithoutSpace", | |
// skipRequests: "request name with space,requestNameWithoutSpace" | |
} | |
} | |
}).on('start', function (err, args) { // on start of run, log to console | |
console.log('start'); | |
}).on('console', function (err, args) { | |
if (err) { return; } | |
logs.push(args.messages); | |
}).on('done', function (err, summary) { | |
if (err || summary.error) { | |
console.error('collection run encountered an error.'); | |
} | |
else { | |
console.log('collection run completed.'); | |
} | |
fs.writeFileSync("results.txt", logs.join("\r\n")); | |
}) | |
.on('request', (error, data) => { | |
if (error) { | |
console.log(error); | |
return; | |
} | |
const requestName = data.item.name.replace(/[^a-z0-9]/gi, '-'); | |
const randomString = Math.random().toString(36).substring(7); | |
const fileName = `response-${requestName}-new.txt`; | |
const content = data.response.stream.toString(); | |
fs.writeFile(fileName, content, function (error) { | |
if (error) { | |
console.error(error); | |
} | |
}); | |
/// TODO: all global error handling | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment