NewmanPostman_VSTS_Task icon indicating copy to clipboard operation
NewmanPostman_VSTS_Task copied to clipboard

Add the ability to set the html report name to collection name being run

Open Scott-Emberson opened this issue 5 years ago • 3 comments

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.

Scott-Emberson avatar May 30 '19 08:05 Scott-Emberson

I think the collection name is passed into the GetTestRunner method: https://github.com/carlowahlstedt/NewmanPostman_VSTS_Task/blob/6f2fe4696bb2a99e361a6bc0f6f23a1af7d4b205/NewmanPostman/newmantask.ts#L6

yossarian123 avatar Jun 12 '19 15:06 yossarian123

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 avatar Jun 12 '19 20:06 Scott-Emberson

@Scott-Emberson if I understand this correctly you'd like to:

  1. Add a checkbox labeled: "Set HTML Report Name to the Collection Name"
  2. 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:

  1. You want to be able to set "Reporter Html Export", "Reporter Json Export", and "Reporter JUnit Export"

Questions I'm unsure about:

  1. 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?
  2. 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:

  1. Add a boolean option in task.json for the setting
  2. Get the option globally and reuse it
  3. Your code snippet is close. You need to:
    1. reorg the 3 types being picked up now to be together
    2. make sure we're using if/else so we pickup both cases
    3. 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]);
    }

carlowahlstedt avatar Jun 28 '19 03:06 carlowahlstedt