Skip to content

Instantly share code, notes, and snippets.

@ksakae1216
Created March 4, 2019 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksakae1216/424f8bb734249e26cd924cc69128c302 to your computer and use it in GitHub Desktop.
Save ksakae1216/424f8bb734249e26cd924cc69128c302 to your computer and use it in GitHub Desktop.
import { browser } from 'protractor';
import fs = require('fs');
declare var module: NodeModule;
var myReporter = {
specDone: function (result) {
if (result.failedExpectations.length > 0) {
browser.getProcessedConfig().then(function (config) {
browser.takeScreenshot().then(function (png) {
var dirPath = './reports/screenshots/';
if (!fs.existsSync('./reports')) {
fs.mkdirSync('./reports');
if (!fs.existsSync(dirPath))
fs.mkdirSync(dirPath);
}
var fileName = (config.capabilities.browserName + '-' + result.fullName).replace(/[\/\\]/g, ' ').substring(0, 230);
var stream = fs.createWriteStream(dirPath + fileName + '.png');
stream.write(new Buffer(png, 'base64'));
stream.end();
}, function (error) {
console.log("failed to take screenshot");
})
})
}
}
}
module.exports = myReporter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment