Skip to content

Instantly share code, notes, and snippets.

@masonmark
Last active April 13, 2017 13:56
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 masonmark/2332c1238a2fa70b5e4fcfffdcd76ca3 to your computer and use it in GitHub Desktop.
Save masonmark/2332c1238a2fa70b5e4fcfffdcd76ca3 to your computer and use it in GitHub Desktop.
example of a function to take a screenshot from within a Protractor 5 ( / Selenium 3) test case
function takeScreenShot(optionalFileNameFragment) {
return browser.takeScreenshot().then(function (pngData) {
var fragment = '' + (optionalFileNameFragment || "screenshot");
var now = new Date();
var fullName = fragment + "-" + now.toISOString() + ".png";
var fullPath = (process.env.CIRCLE_ARTIFACTS || "/tmp") + "/" + fullName;
var stream = fs.createWriteStream(fullPath);
stream.write(new Buffer(pngData, 'base64'));
stream.end();
console.log("wrote screenshot: " + fullPath)
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment