Skip to content

Instantly share code, notes, and snippets.

@zamber
Last active August 29, 2015 13:58
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 zamber/9951669 to your computer and use it in GitHub Desktop.
Save zamber/9951669 to your computer and use it in GitHub Desktop.
DalekJS + Anvil -> screenshots for a dir full of .html files
/*
Iterate over the static frontend and make screenshots.
Point Anvil to the prod build dir where index.html is.
*/
// Get IP for ievms + anvil
// https://stackoverflow.com/questions/3653065/get-local-ip-address-in-node-js
var os = require('os');
var ip;
var ifaces = os.networkInterfaces();
for (var dev in ifaces) {
var alias = 0;
ifaces[dev].forEach( function (details) {
if (details.family == 'IPv4' & dev == 'en0') {
console.log(dev + (alias ? ':' + alias : ''), details.address);
ip = details.address;
++alias;
}
});
}
var root = 'http://prod.' + ip + '.xip.io/'; // Anvil url
var path = 'build/prod/'; // Relative path for building the pages array
// get files from static preview path
var fs=require('fs');
var pages = fs.readdirSync(path)
.filter( function (file) { return file.substr(-5) == '.html' })
.filter( function (file) { return file.indexOf('index.html') == -1 });
console.log(pages);
function testfunc(root, page) {
return function (test) {
test
.open(root + page)
.screenshot('screens/' + page.split('.')[0] + '-:browser' + '.png')
.log.message( 'Got it!' )
.done();
}
}
var exp = {};
for (var page in pages) {
var txt = 'Shoot for ' + root + pages[page];
exp[txt] = testfunc(root, pages[page]);
}
module.exports = exp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment