Protractor provides the ability to take a screenshot with browser.takeScreenshot() function, You can also save the screenshot that you have taken.
// take a screenshot
browser.takeScreenshot().then(function (png) {
// create stream for writing the image
var stream = createWriteStream("exception.png");
// write the stream to local file
stream.write(new Buffer(png, 'base64'));
// close the stream
stream.end();
});
Complete program for taking a screenshot.
import{createWriteStream} from 'fs'
import { browser, by, element, ExpectedConditions} from 'protractor'
describe('Protractor Typescript Demo', function() {
browser.ignoreSynchronization = true; // for non-angular websites
it('get Cookie test in Protractor', function() {
browser.get("https://google.com")
// take screenshot
browser.takeScreenshot().then(function (png) {
var stream = createWriteStream("exception.png");
stream.write(new Buffer(png, 'base64'));
stream.end();
});
});
});
I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.