Skip to content

Instantly share code, notes, and snippets.

@PrashantBhatasana
Last active June 6, 2019 08:38
Show Gist options
  • Save PrashantBhatasana/8fd7a10192eee3d6bf31a6dd1b968927 to your computer and use it in GitHub Desktop.
Save PrashantBhatasana/8fd7a10192eee3d6bf31a6dd1b968927 to your computer and use it in GitHub Desktop.
Demo protractor configuration file with `jasmine-reporters` intergation.
var jasmineReporters = require('jasmine-reporters');
exports.config = {
// The address of a running selenium server.
seleniumAddress: 'http://localhost:4444/wd/hub',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'firefox'
},
// Spec patterns are relative to the location of the spec file. They may
// include glob patterns.
suites: {
login: 'tests/e2e/home/login.spec.js'
},
// Options to be passed to Jasmine-node.
jasmineNodeOpts: {
showColors: true, // Use colors in the command line report.
},
baseUrl: "https://hidden-bayou-97469.herokuapp.com/us/#!/",
/******************** jasmine-reporters */
onPrepare: function () {
jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
consolidateAll: true,
savePath: './',
filePrefix: 'xmlresults'
}));
var fs = require('fs-extra');
fs.emptyDir('screenshots/', function (err) {
console.log(err);
});
jasmine.getEnv().addReporter({
specDone: function (result) {
if (result.status == 'failed') {
browser.getCapabilities().then(function (caps) {
var browserName = caps.get('browserName');
browser.takeScreenshot().then(function (png) {
var stream = fs.createWriteStream('screenshots/' + browserName + '-' + result.fullName + '.png');
stream.write(new Buffer(png, 'base64'));
stream.end();
});
});
}
}
});
},
onComplete: function () {
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);
});
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment