Skip to content

Instantly share code, notes, and snippets.

@excenter
Created January 21, 2016 19:55
Show Gist options
  • Select an option

  • Save excenter/249840df70e813dff268 to your computer and use it in GitHub Desktop.

Select an option

Save excenter/249840df70e813dff268 to your computer and use it in GitHub Desktop.
Convenience/helper function for taking screenshots using Protractor/WebDriver and NodeJS
// Example usage to check visibility (using Jasmine and Protractor)
describe('My page', function() {
it('displays "Hello World" after clicking something on the page', function() {
saveScreenshot('C:\\Users\\omouse\\Documents\\test-step-1.png');
clickSomethingOnPage();
saveScreenshot('C:\\Users\\omouse\\Documents\\test-step-2.png');
var helloWorld = element(by.css('.message'));
var helloWorldIsVisible = protractor.ExpectedConditions.visibilityOf(helloWorld);
expect(helloWorldIsVisible()).toBe(true);
});
});
// for use with Protractor/Webdriver
var fs = require('fs');
var path = require('path');
var saveScreenshot = function(pathname) {
browser.takeScreenshot().then(function(png) {
var file = path.resolve(pathname);
fs.writeFileSync(file, png, { encoding: 'base64' }, console.log);
});
};
@excenter
Copy link
Copy Markdown
Author

making an NPM module that utilizes this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment