Casperjs random delay
I am using casperjs and I want to navigate the site in rantom spans. I made a code like this, but it didn't work:
function getRandomIntFromRange(min, max) {
return Math.round(Math.random() * (max - min)) + min;
}
var casper = require('casper').create();
casper.start('http://stackoverflow.com/');
casper.on('remote.message', function(msg) {
this.echo('remote message caught: ' + msg);
});
casper.then(function() {
for (i=0; i<=5; i++) {
delay = getRandomIntFromRange(1000, 5000);
this.wait(delay, (
function(j) {
return function() {
this.echo('Test ' + j + '; delay: ' + delay);
};
})(i));
}
});
casper.run();
The output was as follows:
Test 0; delay: 1320
Test 1; delay: 1320
Test 2; delay: 1320
Test 3; delay: 1320
Test 4; delay: 1320
Test 5; delay: 1320
+3
source to share