Reputation: 11
While trying to execute conf.js file in protector everything working file while generating report from xml to html screenshot not attached to html report. Also why onprepare and onComplete excuted by default . Wants to know about implementaion of these.
Any clarification will be helpfull with related github source code.
exports.config = {
framework: 'jasmine2',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['spec.js'],
capabilities: {
browserName: 'chrome'
},
onPrepare: function () {
console.log('on prepared called');
var jasmineReporters = require('jasmine-reporters');
jasmine.getEnv().addReporter(new . jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
//savePath: '.',
filePrefix: 'xmlresults.xml'
}));
},
onComplete: function() {
console.log('on complete called');
var browserName, browserVersion;
var capsPromise = browser.getCapabilities();
capsPromise.then(function (caps) {
browserName = caps.get('browserName');
browserVersion = caps.get('version');
platform = caps.get('platform');
var HTMLReport = require('protractor-html-reporter-2');
testConfig = {
reportTitle: 'Protractor Test Execution Report',
outputPath: './',
outputFilename: 'ProtractorTestReport',
screenshotPath: './screenshots',
testBrowser: browserName,
browserVersion: browserVersion,
modifiedSuiteName: false,
screenshotsOnlyOnFailure: true,
testPlatform: platform
};
new HTMLReport().from('xmlresults.xml', testConfig);
});
}
}
Upvotes: 0
Views: 3316
Reputation: 2348
onPrepare and onComplete are referred to as lifecycle hooks and are executed at particular stages of your execution. There are many lifecycle hooks available to protractor through various means including from the jasmine reporters you declare, as you've mentioned.
Overview of lifecycle hooks and the order they are triggered
--- beforeLaunch
--- onPrepare (set in conf) ***reporters initialized here
--- jasmineStarted (set in reporter)
--- beforeAll
--- suiteStarted (set in reporter)
--- specStarted (set in reporter)
--- beforeEach (set in testFile)
+++ afterEach (set in testFile)
+++ specDone (set in reporter)
+++ suiteDone (set in reporter)
+++ afterAll
+++ jasmineDone (set in reporter)
+++ onComplete (set in conf)
+++ afterLaunch
It's not clear what your issue is from your question but I am assuming you are having issues with your html reporter because you are declaring it in the onComplete. Jasmine reporters have a few important lifecycle hooks themselves: (jasmineStarted, jasmineDone, suiteStarted, suiteDone, specStarted, specDone) but, if you look at the above overview I pasted, you can see that those reporter lifecycle hooks all take place before the onComplete is called. If you declare your reporter in the onComplete instead of the onPrepare these lifecycle stages will already has passed and no actions will be taken on them.
You can read more about the purpose of the Protractor lifecycle hooks in the attached link. https://github.com/angular/protractor/blob/master/exampleTypescript/conf.ts
and the Jasmine Reporter lifecycle hooks here. https://jasmine.github.io/api/3.3/Reporter.html
Hope that answers you questions but let me know if I have misunderstood.
Upvotes: 4