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();
		});
	});
});

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Recent Addition

new tutorial Selenium Online Training : Our next online training course for Selenium with Java starts from 17th December 2018.

You can attend first 3 classes for free, the total course fee is INR 10,000

The course time would be 8.00 PM(IST) for the first three classes

If you are interested to learn, then you can join the course by sending email to chercher.tech@gmail.com

or Register below


 
Join My Facebook Group
Join Group