Skip to content

Instantly share code, notes, and snippets.

@amaxwell01
Created May 1, 2016 18:32
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 amaxwell01/fe4aee9a0516d11c90e8835ef786caf4 to your computer and use it in GitHub Desktop.
Save amaxwell01/fe4aee9a0516d11c90e8835ef786caf4 to your computer and use it in GitHub Desktop.
Takes provided URL passed as argument and make full height screenshots of this page * with several viewport widths using Nightwatch.js with Selenium.
/*
* Takes provided URL passed as argument and make full height screenshots of this page
* with several viewport widths using Nightwatch.js with Selenium.
*
* These viewport widths are taken from common android and iOS devices. Modify as needed.
*
* Takes an optional second argument for the path where screenshots are saved.
*
* Usage:
* $ node node_modules/.bin/nightwatch -t viewport-shots.js http://example.com
* $ node node_modules/.bin/nightwatch -t viewport-shots.js http://example.com directory/to/save
*/
module.exports = {
"Viewport Screenshots" : function (browser) {
// Make sure a URL has been passed
if (process.argv.length < 5) {
console.log('No URL was specified');
browser.end();
}
var url = process.argv[4],
save_directory = 'screenshots',
viewport_widths = [240, 320, 360, 568, 603, 640, 768, 800, 960, 1024, 1280, 1400, 1600, 1920];
// Optional argument - path to save
if (process.argv.length >= 6) {
save_directory = process.argv[5];
}
browser.url(url).waitForElementVisible('body', 1000);
viewport_widths.forEach(function(width){
browser
.resizeWindow(width, 300)
.saveScreenshot(save_directory + '/' + width + '.png')
});
browser.end();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment