Created
March 4, 2019 13:54
-
-
Save ksakae1216/424f8bb734249e26cd924cc69128c302 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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