Created
October 4, 2015 16:30
-
-
Save philmander/9a7b98763027bd923758 to your computer and use it in GitHub Desktop.
CasperJS Website Resolution Tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var casper = require('casper').create({ | |
verbose: true, | |
logLevel: 'info' | |
}); | |
var page = require('webpage').create(); | |
var utils = require('utils'); | |
//args | |
var base = casper.cli.get('out'); | |
var width = parseInt(casper.cli.get("width")); | |
var height = parseInt(casper.cli.get("height")); | |
var addr = casper.cli.get('addr'); | |
//usage (if no args) | |
if(!width && !height && !base && !addr) { | |
casper.log('Usage: casperjs resolution-test.js --width=[width] --height=[height] -addr=[webpage address] --out=[output base filename]', 'info'); | |
casper.exit(); | |
} | |
//check args | |
if(isNaN(width)) { | |
throw new Error('Missing width (--width)'); | |
} | |
if(isNaN(height)) { | |
throw new Error('Missing height (--height)'); | |
} | |
if(!base) { | |
throw new Error('Missing output file name (--output)'); | |
} | |
if(!addr) { | |
throw new Error('Missing address to test (--addr)'); | |
} | |
var msg = utils.format('Taking screenshot from %s at %s x %s:', addr, width, height); | |
casper.log(msg, 'info'); | |
page.viewportSize = { width: width, height: height }; | |
page.clipRect = { top: 0, left: 0, width: width, height: height }; | |
page.open(addr, function() { | |
var filename = utils.format('%s.%sx%s.png', base, width, height); | |
casper.log('Saving screenshot to: ' + filename, 'info'); | |
page.render(filename); | |
phantom.exit(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment