Skip to content

Instantly share code, notes, and snippets.

@dhendo
Created July 17, 2013 13:10
Show Gist options
  • Save dhendo/6020429 to your computer and use it in GitHub Desktop.
Save dhendo/6020429 to your computer and use it in GitHub Desktop.
Run Chimera 6 times - 3x loading using a url, 3x by passing a snippet of html
<html><head></head><body><div id="theDiv"><!-- Horizontal Layout -->
<table style="border-collapse: collapse; " cellpadding="5">
<tr>
<td valign="middle" style="text-align: center; font-family: sans-serif; font-size: 12px;
border: 1px solid #ccc; max-width: 150px;">
<a href="http://demostore.triggeredmessaging.com/canon-digital-rebel-xt-8mp-digital-slr-camera-with-ef-s-18-55mm-f3-5-5-6-lens-black.html" style="text-decoration: none; color:#444;"><img src="http://s4f97beb731337.img.gostorego.com/802754/cdn/media/s4/f9/7b/eb/73/13/37/catalog/product/cache/1/image/370x/9df78eab33525d08d6e5fb8d27136e95/c/a/canon-digital-rebel-xt-8mp-digital-slr-camera-1.jpg"
style="max-width: 175px; max-height: 100px; margin-top: 10px;"/></a>
<br>
<a href="http://demostore.triggeredmessaging.com/canon-digital-rebel-xt-8mp-digital-slr-camera-with-ef-s-18-55mm-f3-5-5-6-lens-black.html"
style="text-decoration: none; color:#444;">CANON DIGITAL REBEL XT 8MP DIGITAL SLR CAMERA: <span style="color:#900;">$550.0</span></a>
</td>
<td valign="middle" style="text-align: center; font-family: sans-serif; font-size: 12px;
border: 1px solid #ccc; max-width: 150px;">
<a href="http://demostore.triggeredmessaging.com/akio-dresser.html" style="text-decoration: none; color:#444;"><img src="http://s4f97beb731337.img.gostorego.com/802754/cdn/media/s4/f9/7b/eb/73/13/37/catalog/product/cache/1/image/370x/9df78eab33525d08d6e5fb8d27136e95/a/k/akio-dresser.jpg"
style="max-width: 175px; max-height: 100px; margin-top: 10px;"/></a>
<br>
<a href="http://demostore.triggeredmessaging.com/akio-dresser.html"
style="text-decoration: none; color:#444;">AKIO DRESSER: <span style="color:#900;">$399.99</span></a>
</td>
<td valign="middle" style="text-align: center; font-family: sans-serif; font-size: 12px;
border: 1px solid #ccc; max-width: 150px;">
<a href="http://demostore.triggeredmessaging.com/magento-red-furniture-set.html" style="text-decoration: none; color:#444;"><img src="http://s4f97beb731337.img.gostorego.com/802754/cdn/media/s4/f9/7b/eb/73/13/37/catalog/product/cache/1/image/370x/9df78eab33525d08d6e5fb8d27136e95/m/a/magento-red-furniture-set.jpg"
style="max-width: 175px; max-height: 100px; margin-top: 10px;"/></a>
<br>
<a href="http://demostore.triggeredmessaging.com/magento-red-furniture-set.html"
style="text-decoration: none; color:#444;">MAGENTO RED FURNITURE SET: <span style="color:#900;">$129.99</span></a>
</td>
<td valign="middle" style="text-align: center; font-family: sans-serif; font-size: 12px;
border: 1px solid #ccc; max-width: 150px;">
<a href="http://demostore.triggeredmessaging.com/1tb-7200rpm.html" style="text-decoration: none; color:#444;"><img src="http://s4f97beb731337.img.gostorego.com/802754/cdn/media/s4/f9/7b/eb/73/13/37/catalog/product/cache/1/image/370x/9df78eab33525d08d6e5fb8d27136e95/w/e/western-digital-1tb-hd-7200rpm.jpg"
style="max-width: 175px; max-height: 100px; margin-top: 10px;"/></a>
<br>
<a href="http://demostore.triggeredmessaging.com/1tb-7200rpm.html"
style="text-decoration: none; color:#444;">WESTERN DIGITAL - 1TB HD - 7200RPM: <span style="color:#900;">$399.0</span></a>
</td>
</tr>
</table>
</div></body></html>
<html><head></head><body><div id="theDiv"><!-- Horizontal Layout -->
<table style="border-collapse: collapse; " cellpadding="5">
<tr>
<td valign="middle" style="text-align: center; font-family: sans-serif; font-size: 12px;
border: 1px solid #ccc; max-width: 150px;">
<a href="http://demostore.triggeredmessaging.com/canon-digital-rebel-xt-8mp-digital-slr-camera-with-ef-s-18-55mm-f3-5-5-6-lens-black.html" style="text-decoration: none; color:#444;"><img src="http://s4f97beb731337.img.gostorego.com/802754/cdn/media/s4/f9/7b/eb/73/13/37/catalog/product/cache/1/image/370x/9df78eab33525d08d6e5fb8d27136e95/c/a/canon-digital-rebel-xt-8mp-digital-slr-camera-1.jpg"
style="max-width: 175px; max-height: 100px; margin-top: 10px;"/></a>
<br>
<a href="http://demostore.triggeredmessaging.com/canon-digital-rebel-xt-8mp-digital-slr-camera-with-ef-s-18-55mm-f3-5-5-6-lens-black.html"
style="text-decoration: none; color:#444;">CANON DIGITAL REBEL XT 8MP DIGITAL SLR CAMERA: <span style="color:#900;">$550.0</span></a>
</td>
<td valign="middle" style="text-align: center; font-family: sans-serif; font-size: 12px;
border: 1px solid #ccc; max-width: 150px;">
<a href="http://demostore.triggeredmessaging.com/akio-dresser.html" style="text-decoration: none; color:#444;"><img src="http://s4f97beb731337.img.gostorego.com/802754/cdn/media/s4/f9/7b/eb/73/13/37/catalog/product/cache/1/image/370x/9df78eab33525d08d6e5fb8d27136e95/a/k/akio-dresser.jpg"
style="max-width: 175px; max-height: 100px; margin-top: 10px;"/></a>
<br>
<a href="http://demostore.triggeredmessaging.com/akio-dresser.html"
style="text-decoration: none; color:#444;">AKIO DRESSER: <span style="color:#900;">$399.99</span></a>
</td>
<td valign="middle" style="text-align: center; font-family: sans-serif; font-size: 12px;
border: 1px solid #ccc; max-width: 150px;">
<a href="http://demostore.triggeredmessaging.com/magento-red-furniture-set.html" style="text-decoration: none; color:#444;"><img src="http://s4f97beb731337.img.gostorego.com/802754/cdn/media/s4/f9/7b/eb/73/13/37/catalog/product/cache/1/image/370x/9df78eab33525d08d6e5fb8d27136e95/m/a/magento-red-furniture-set.jpg"
style="max-width: 175px; max-height: 100px; margin-top: 10px;"/></a>
<br>
<a href="http://demostore.triggeredmessaging.com/magento-red-furniture-set.html"
style="text-decoration: none; color:#444;">MAGENTO RED FURNITURE SET: <span style="color:#900;">$129.99</span></a>
</td>
<td valign="middle" style="text-align: center; font-family: sans-serif; font-size: 12px;
border: 1px solid #ccc; max-width: 150px;">
<a href="http://demostore.triggeredmessaging.com/1tb-7200rpm.html" style="text-decoration: none; color:#444;"><img src="http://s4f97beb731337.img.gostorego.com/802754/cdn/media/s4/f9/7b/eb/73/13/37/catalog/product/cache/1/image/370x/9df78eab33525d08d6e5fb8d27136e95/w/e/western-digital-1tb-hd-7200rpm.jpg"
style="max-width: 175px; max-height: 100px; margin-top: 10px;"/></a>
<br>
<a href="http://demostore.triggeredmessaging.com/1tb-7200rpm.html"
style="text-decoration: none; color:#444;">WESTERN DIGITAL - 1TB HD - 7200RPM: <span style="color:#900;">$399.0</span></a>
</td>
</tr>
</table>
</div></body></html>
var Chimera = require(__dirname + '/../lib/main').Chimera;
var c = new Chimera();
var fs = require('fs');
var html;
html = fs.readFileSync('./out.html', 'utf8');
var doAction = function (callback, count, type) {
console.log('***********************')
console.log('Run: ' + count);
console.log('Type: ' + type);
console.log('***********************')
count++;
try{
fs.unlinkSync('logged_out.png');
}catch(ex){}
var options = {
callback: function (err, result) {
try {
// Clip the capture to our Div
c.browser.clipToElement("#theDiv");
// Capture to File
//var imageBuffer = c.browser.captureBytes();
c.capture("logged_out.png");
} catch (e) {
}
if (count < maxRuns) {
setTimeout(function () {
try {
stats = fs.lstatSync('logged_out.png');
if (stats.isFile()) {
console.log('File Found')
}
}
catch (e) {
throw new Error('file not created')
}
fs.unlinkSync('logged_out.png');
c.close();
//c = null;
//c = new Chimera();
doAction(callback, count, type);
}, 1);
return;
} else {
//console.log('-- Type: ' + type +' Count: ' + count + " Maxruns: " + maxRuns);
if(type ==='url'){
c.close();
doAction(callback, 0, 'snippet')
}else{
//c.close();
callback();
}
}
}
}
if(type == 'url'){
options.url = 'http://www.google.com';
}else{
options.html = html;
}
c.perform(options);
};
var maxRuns = 3;
doAction(function (err, data) {
console.log(err);
console.log('%%%%%%%%%%%%%%%%%%%%%%%\ndone\n%%%%%%%%%%%%%%%%%%%%%%');
}, 0, 'url');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment