Skip to content

Instantly share code, notes, and snippets.

@mrosati84
Last active August 3, 2016 16:37
Show Gist options
  • Save mrosati84/6038290 to your computer and use it in GitHub Desktop.
Save mrosati84/6038290 to your computer and use it in GitHub Desktop.
Test automation for responsive layout using PhantomJS
/*
requires: phantomjs, async
usage: phantomjs capture.js
*/
var async = require('async'),
sizes = [
[320, 480],
[1024, 768],
[1280, 800],
[1280, 1024],
[1440, 900],
[1920, 1080]
];
function capture(sizes, callback) {
var page = require('webpage').create();
page.viewportSize = {
width: sizes[0],
height: sizes[1]
};
page.zoomFactor = 1;
page.open('http://localhost.youtsite.com/', function (status) {
var filename = sizes[0] + 'x' + sizes[1] + '.png';
page.render('./screenshots/' + filename);
page.close();
callback.apply();
});
}
async.eachSeries(sizes, capture, function (e) {
if (e) console.log(e);
console.log('done!');
phantom.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment