NewmanPostman_VSTS_Task
NewmanPostman_VSTS_Task copied to clipboard
Add the ability to set the html report name to collection name being run
Add an additional option onto the HTML report location so you can have the code set the HTML name to the collection being run.
I have started to look at it, but unsure where I could pick up the collection name.
I think the collection name is passed into the GetTestRunner method: https://github.com/carlowahlstedt/NewmanPostman_VSTS_Task/blob/6f2fe4696bb2a99e361a6bc0f6f23a1af7d4b205/NewmanPostman/newmantask.ts#L6
Thanks @yossarian123 I am not too good with ts but would this work?
if (reporterReportNameToCollectionName === true) { let reporterHtmlExport = tl.getPathInput('reporterHtmlExport'); newman.argIf(typeof reporterHtmlExport != 'undefined' && tl.filePathSupplied('reporterHtmlExport'.concat("\\",collectionToRun.toString())), ['--reporter-html-export', reporterHtmlExport]); let reporterJsonExport = tl.getPathInput('reporterJsonExport'); newman.argIf(typeof reporterJsonExport != 'undefined' && tl.filePathSupplied('reporterJsonExport'.concat("\\",collectionToRun.toString())), ['--reporter-json-export', reporterJsonExport]); let reporterJUnitExport = tl.getPathInput('reporterJUnitExport', false, false); newman.argIf(typeof reporterJUnitExport != 'undefined' && tl.filePathSupplied('reporterJUnitExport'.concat("\\",collectionToRun.toString())), ['--reporter-junit-export', reporterJUnitExport]); }
@Scott-Emberson if I understand this correctly you'd like to:
- Add a checkbox labeled: "Set HTML Report Name to the Collection Name"
- When running newman, insert the collection name as the name of the report generated
Things that seem added based on your code snippet from above:
- You want to be able to set "Reporter Html Export", "Reporter Json Export", and "Reporter JUnit Export"
Questions I'm unsure about:
- Each of the above listed export options are paths, where the help says the following and all are similar: "Specify a path where the output JSON file will be written to disk. If not specified, the file will be written to newman/ in the current working directory." So my question is, can you specify a file when the docs say path?
- Given that your setting all three, would it be helpful to append the type after the collection name for clarity? So [collection-name]-json.json
Steps to complete this:
- Add a boolean option in task.json for the setting
- Get the option globally and reuse it
- Your code snippet is close. You need to:
- reorg the 3 types being picked up now to be together
- make sure we're using if/else so we pickup both cases
- try to reduce the code to be reused as much as possible where it is still clear what is going on
A quick draft of your section of code refactored would be something like:
let reporterHtmlExport = tl.getPathInput('reporterHtmlExport');
let reporterJsonExport = tl.getPathInput('reporterJsonExport');
let reporterJUnitExport = tl.getPathInput('reporterJUnitExport', false, false);
let useCollectionNameForReportName;
if (useCollectionNameForReportName === true) {
newman.argIf(typeof reporterHtmlExport != 'undefined' && tl.filePathSupplied('reporterHtmlExport'), ['--reporter-html-export', reporterHtmlExport.concat("\\", collectionToRun)]);
newman.argIf(typeof reporterJsonExport != 'undefined' && tl.filePathSupplied('reporterJsonExport'), ['--reporter-json-export', reporterJsonExport.concat("\\", collectionToRun)]);
newman.argIf(typeof reporterJUnitExport != 'undefined' && tl.filePathSupplied('reporterJUnitExport'), ['--reporter-junit-export', reporterJUnitExport.concat("\\", collectionToRun)]);
}
else {
newman.argIf(typeof reporterHtmlExport != 'undefined' && tl.filePathSupplied('reporterHtmlExport'), ['--reporter-html-export', reporterHtmlExport]);
newman.argIf(typeof reporterJsonExport != 'undefined' && tl.filePathSupplied('reporterJsonExport'), ['--reporter-json-export', reporterJsonExport]);
newman.argIf(typeof reporterJUnitExport != 'undefined' && tl.filePathSupplied('reporterJUnitExport'), ['--reporter-junit-export', reporterJUnitExport]);
}