diff --git a/README.markdown b/README.markdown index 7497497..128b844 100644 --- a/README.markdown +++ b/README.markdown @@ -196,3 +196,31 @@ onPrepare: function() { } ``` +You can also use the `properties` option to add properties on report. + +```javascript +multiCapabilities: [ + {browserName: 'firefox'}, + {browserName: 'chrome'} +], +framework: 'jasmine2', +onPrepare: function() { + var jasmineReporters = require('jasmine-reporters'); + + // returning the promise makes protractor wait for the reporter config before executing tests + return browser.getProcessedConfig().then(function(config) { + // you could use other properties here if you want, such as platform and version + var browserName = config.capabilities.browserName; + + var junitReporter = new jasmineReporters.JUnitXmlReporter({ + consolidateAll: false, + savePath: 'testresults', + properties: { + capabilities: browserName, + } + }); + jasmine.getEnv().addReporter(junitReporter); + }); +} +``` + diff --git a/src/junit_reporter.js b/src/junit_reporter.js index 3803802..68b0602 100644 --- a/src/junit_reporter.js +++ b/src/junit_reporter.js @@ -141,6 +141,8 @@ * @param {boolean} [useFullTestName] whether to use the fully qualified Test * name for the TestCase name attribute, ie "Suite Name Spec Name" not * "Spec Name" (default: false) + * @param {object} [properties] allows you to add custom properties within + * the report xml (Example: { capabilities: 'chrome', suiteName: 'TestCase' }) * @param {string} [filePrefix] is the string value that is prepended to the * xml output file (default: junitresults-) * NOTE: if consolidateAll is true, the default is simply "junitresults" and @@ -179,6 +181,7 @@ self.consolidateAll = self.consolidate !== false && (options.consolidateAll === UNDEFINED ? true : options.consolidateAll); self.useDotNotation = options.useDotNotation === UNDEFINED ? true : options.useDotNotation; self.useFullTestName = options.useFullTestName === UNDEFINED ? false : options.useFullTestName; + self.properties = options.properties || {}; if (self.consolidateAll) { self.filePrefix = options.filePrefix || "junitresults"; } else { @@ -448,7 +451,9 @@ xml += ' package="' + self.package + '"'; } xml += ">"; - + if (options.properties) { + xml += propertiesAsXml(options.properties); + } for (var i = 0; i < suite._specs.length; i++) { xml += specAsXml(suite._specs[i]); } @@ -515,5 +520,13 @@ if (filename.substr(-4) !== ".xml") { filename += ".xml"; } self.writeFile(filename, (getPrefix(testSuitesResults) + text + suffix)); } + function propertiesAsXml (props) { + var propertiesBody = "\n "; + for (var prop in props) { + propertiesBody += '\n '; + } + propertiesBody += "\n "; + return propertiesBody; + } }; })(this);