Skip to content

Instantly share code, notes, and snippets.

@rbg246
Created June 1, 2015 09:46
Show Gist options
  • Save rbg246/0ecc8d747af9ec2438d7 to your computer and use it in GitHub Desktop.
Save rbg246/0ecc8d747af9ec2438d7 to your computer and use it in GitHub Desktop.
CasperJS Test File - iterating through a Data Object specifying multiple viewports for each page
module.exports = {
clientScripts : [
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/lodash/index.js'
],
viewportSize : {
width: 1600,
height: 1200
},
timeout : 50000,
// verbose: true,
// logLevel: 'debug'
};
{
"name": "casper-tests",
"version": "0.0.0",
"description": "",
"main": "start.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Richard Gaunt",
"license": "ISC",
"dependencies": {
"jquery": "^2.1.4",
"lodash" : "*",
"spooky": "^0.2.5"
}
}
var defaultViewports = [
{
width : 320,
height : 480
},
{
width: 1024,
height: 768
},
{
width: 1600,
height: 1200
}
];
module.exports = [
{
url : 'http://www.richardgaunt.com',
viewports : defaultViewports
},
{
url :'http://www.alfresco.com',
viewports : defaultViewports
}
];
var config = require('./config');
var pages = require('./pageData');
var casper = require('casper').create(config);
casper.start();
casper.eachThen(pages, function (response) {
var url = response.data.url;
var viewports = response.data.viewports;
casper.eachThen(viewports, function (res) {
var viewport = res.data;
casper.thenOpen(url, function (response) {
console.log(url + ' - ' + viewport.width + 'x' + viewport.height);
});
});
});
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment