Created
July 3, 2014 13:09
-
-
Save vilmosioo/2bcb091bc3d98027a75e to your computer and use it in GitHub Desktop.
Protractor screenshots
This file contains hidden or 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
var fs = require('fs'), | |
path = require('path'); | |
afterEach(function(){ | |
var passed = jasmine.getEnv().currentSpec.results().passed(); | |
// Replace all space characters in spec name with dashes | |
var specName = jasmine.getEnv().currentSpec.description.replace(/ /g, '-'), | |
baseFileName = specName, | |
screenshotsDir = path.resolve(__dirname + '../screenshots/'); | |
if (!passed) { | |
// Create screenshots dir if doesn't exist | |
if (!fs.existsSync(screenshotsDir)) { | |
fs.mkdirSync(screenshotsDir); | |
} | |
var file = path.resolve(screenshotsDir + '/' + baseFileName + '.png'); | |
browser.takeScreenshot().then(function (png) { | |
console.log('Writing file ' + file); | |
fs.writeFileSync(file, png, {encoding: 'base64'}, console.log); | |
}, console.log); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment