Join us on :

Screenshot in Protractor

Protractor provides the ability to take a screenshot with browser.takeScreenshot() function, You can also save the screenshot that you have taken.


// take screen shot
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 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();
		});
	});
});

Protractor Interview Questions

About Author

Article is written by Pavan (a) KarthiQ. Well, I am serving notice period in an MNC, Bangalore. I thought to enrich every person knowledge a little, I always have a feeling, when we teach something, we will learn more than what you know. Knowledge is the only thing that doubles when you spend it.

I have also created the reporter for Protractor Jasmine. Use for your projects without any hesitation

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions