// at the top of the test spec: var fs = require('fs'); // ... other code // abstract writing screen shot to a file function writeScreenShot(data, filename) { var stream = fs.createWriteStream(filename); stream.write(new Buffer(data, 'base64')); stream.end(); } // ... // within a test: browser.takeScreenshot().then(function (png) { writeScreenShot(png, 'exception.png'); });